@codestorywithMIK

Apologies if I have made silly mistakes. As I mentioned, I am attending a function of my friend this weekend and travelling, making videos during travel and in a different place is sometimes challenging and due to rush, I hope you guys will understand. Thanks to each one of you who pointed this out in the comments. ❀❀❀

A small correction, thanks to all of you guys for pointing those out :
16:41  If we are writing ------> int ch3 = n - ch1 - ch2 , this already means that ch1 + ch2 + ch3 = n that you're checking in if condition
Instead the if condition would be 
if(ch3 <= limit) ways++;


With Gratitude -πŸ™β€πŸ™
Tumhara MIK
#codestorywithmik #codestorywithMIK #mik #MIK

@aws_handles

Came here for linear approach. What a fine explanation πŸ”₯πŸ”₯πŸ”₯

@techmind9608

perfect way ,,,  "teach how to catch fish instead of giving fish...".  you are Teaching

@ManasiKamble-x7s

Just wanted to say thank you! You are truly awesome. I've been watching your videos for the past 5 days, and the way you explain and simplify problems is simply amazing. It’s helped me so much in understanding how to approach problems better. Truly grateful for your content!

@Pratham_Rathod._

man, i tell you one thing... i used to hate DSA... it was like a burden to me but now because of you, slowly but surely i am starting to enjoy it...  i am loving solving DSA problems every day and it has become like a routine for me... thank you sooo much!!

@interestingduniya555

Speechless after watching this masterpiece explanation ❀❀❀❀

@suryasaipalthi

Thank you mik, these detailed explanations are what makes me think better.

@saisree04

Amazing explanation, what's more impressive is the logic and how easily you have explained it

@umang-x8k

O(1) Approach 😱😱






class Solution {
    const int MOD = 1e9 + 7;
    long long C(long long n) {
        if (n < 0) return 0;
        return (n * (n - 1)) / 2;
    }

public:
    long long distributeCandies(int n, int limit) {
        long long total = C(n + 2 + 1); // C(n+2, 2)
        long long over1 = 3 * C(n - limit - 1 + 2 + 1); // each child > limit
        long long over2 = 3 * C(n - 2 * (limit + 1) + 2 + 1); // any two > limit
        long long over3 = C(n - 3 * (limit + 1) + 2 + 1); // all three > limit

        long long ans = total - over1 + over2 - over3;
        return max(0LL, ans); // ensure non-negative
    }
};

@AadishJangid

bhaiya from today i started my dsa journey and saw your this video and just feeling dumb  ;what a video- mindblowing ; i will come back you to comment my journey update .

@Resham298

highly appreciate your efforts and dedication πŸ˜‡

@adarshsinghchauhan5978

You earned a fan today .
Great explanation mate ❀

@vipulmaheshwari3568

This marks my 2 days streak. I have started after so many months and hope I will continue it in the coming days.

@rohitprajapat4905

Bhai , you have amazing skill of teaching .

@NEUTRON-h5t

thank you sir your channel is way too underrated i will tell about this channel to my college friends 
finally understood this question, i was on solution tab of leetcode and was not understanding any solution at the same time your channel was suggested in out leetcoders whatsapp group 
after that i came here  for the solution explanation and this 40 min was worth it 😊

@AdityaSharma-ox9dv

Bhaiya , you are really a motivation and inspiration for me.

@adityashriwal5378

Thank you so much, love the way of your explanation. This is real DSA.

@shushant1847

Hey Mik, it would be great if you could share us the pdfs of the iPad notes it will definitely make the revision easier of these type of Questions which students are not being able to handle on the first go!

@GurpreetSingh-mr4jp

Best explanation πŸ‘πŸ» make every thing so much easy and clear

@dayashankarlakhotia4943

Leetcode weekly contest qn.no.4 segment tree is best problem please make video πŸŽ‰β€