Subarray Sums Divisible by K | Brute Force | Optimal | Easy Explanation | codestorywithMIK

Поделиться
HTML-код
  • Опубликовано: 3 ноя 2024

Комментарии • 203

  • @varunyadav6560
    @varunyadav6560 Год назад +41

    Best video on youtube to understand the concept of this question..Thank you so much brother 💖

  • @thexzavier8283
    @thexzavier8283 Год назад +40

    Bruv don't stop uploading you are gonna get that 1M in no time, the way you explained all the mathematical stuff was too good👍

  • @tusharrajput983
    @tusharrajput983 4 месяца назад +3

    I don't care how many subscribers or views you have. But you always have the best way of explaining questions. this is absolute luxury to have all this for free.

  • @VivekPathak-ds2do
    @VivekPathak-ds2do 4 месяца назад +5

    You are the only one jo ye pahle batate ho ki socha kaise jata h.
    Fir prove krte ho. Yhi reason hai ki apki videos baki youtube videos se better hoti h.
    Or aapke concept dekhne k baad mere ko code dekhne ki need aaj tk nhi hui.

    • @parth5183
      @parth5183 4 месяца назад +3

      True, I rarely felt the need to see the code, once I saw his explanation

    • @thekindspill
      @thekindspill 4 месяца назад

      True

  • @ramandeepsingh8464
    @ramandeepsingh8464 9 месяцев назад +16

    kya video hai bhiya OP 🙂lot a way better than all bhiya's & didi's
    here we are using the modulo property which is (a-b)%m = (a%m - b%m + m)%m

  • @pratik.784
    @pratik.784 Год назад +16

    Aapke 1 million jald hoga 🤩

  • @adhikari669
    @adhikari669 Год назад +3

    Bhaya aisa content pure RUclips m khi ni h, na hi aisi awaj ❤️

  • @CodingGuru92
    @CodingGuru92 Месяц назад +1

    I am a huge fan of your teaching style. I have leaned DP also from your videos. You are doing a great job. Keep it up 👍.

  • @AbhayGupta-oz1ix
    @AbhayGupta-oz1ix 3 месяца назад

    Two amazing concepts :
    1,2,3.....n.......m
    1) Sumtill(n) % k == Sumtill(m) % k
    means Sum(n...m) is divisible by k. Got it Thanks to sir.
    2) mod = num % k ;
    if (mod < 0) mod = k - mod // the edge case

  • @drbullah1388
    @drbullah1388 Год назад +3

    Probably the best channel for learning the concept rather than the code
    Bhaiya confidence hai ki agar aapke saath daily LeetCode problems karte raha to kuch hi dino me pura pura khud se solve kar paunga
    Thanks for being there on youtube sharing all your knowledge

    • @codestorywithMIK
      @codestorywithMIK  Год назад

      I am so glad to hear that.
      And indeed we all will grow together 💪

  • @sourav-bisht
    @sourav-bisht 3 месяца назад +1

    No one explains like you bro
    You are the best

  • @himanshusharma9132
    @himanshusharma9132 4 месяца назад +2

    Bruteforce approach - O(n3) passed 70/73 testcases
    Bruteforce approach with O(1) sum testcase passed 69/73 testcases
    Thanks Bhaiya , your approach always improves my logic building skills

  • @tusharrajput983
    @tusharrajput983 4 месяца назад +1

    for anyone wondering about the school division concept : In modular arithmetic, the remainder is always a non-negative number less than the divisor. So (-4 % 7 would be = 3). you are thinking right.
    but In C++ (idk about other languages), the modulus operation with a negative dividend retains the sign of the dividend. Therefore, when you compute -4 % 7, the result will be -4

  • @rahulpandey5094
    @rahulpandey5094 Год назад +3

    best way of explaining I have ever seen . Thank you so much sir .🙏

    • @codestorywithMIK
      @codestorywithMIK  Год назад

      So nice of you. Thank you so much for watching 😇🙏

  • @yashika6248
    @yashika6248 Год назад +1

    After trying so hard to grasp the concept, I finally came across this video and now I am thankful

  • @College_era69
    @College_era69 Месяц назад +2

    kya GOD ho yar ap maja hi ajjata hai..i pick question from striver sheet and if smj ni atta to try finding ur soln ki kya apne same questn pe soln banaya hai if yes toh phle mai apka dkhta
    thnkeww mikkuu bhiayaaa love uu

  • @LifeYetLive
    @LifeYetLive 3 месяца назад +1

    Bhai maja aa gya ❤ itna acche sai toh kisi ne nai samjya abhi tak

  • @nagmakhan3165
    @nagmakhan3165 Год назад +1

    The best explanation on RUclips for this video

  • @kumarimegha9187
    @kumarimegha9187 Год назад +1

    Literally i have no words for this video....your explanation is awesome.... thankyou so much 💖

  • @itsaayush7357
    @itsaayush7357 10 месяцев назад +1

    Bro , your neat code, your clear voice explaination, and your pure intention to make us learn is just unmatchable!
    There are very few people at you tube jo itna shiddat se pdate he.
    Hatts off bro!
    Thank youuu🫂

    • @codestorywithMIK
      @codestorywithMIK  10 месяцев назад

      Means a lot. Thank you so much 🙏🙏❤️❤️

  • @Akash-yr2if
    @Akash-yr2if Год назад +2

    Took around 1.5 hours to understand but finally it got inside my head, Thanks mate. Ye sum agar placement ka puch jarur batunga.

  • @pankajsuryavanshi8332
    @pankajsuryavanshi8332 Год назад +1

    Bro I am addicted to your channel Day by day.what a explanation brute force code explain then code submit then Explain TLE and again optimise approach.no one is teaching from that much depth

    • @pankajsuryavanshi8332
      @pankajsuryavanshi8332 Год назад +1

      Bro u can make more views if u show java code as well like just see striver video.its suggestion

    • @codestorywithMIK
      @codestorywithMIK  Год назад +1

      Sure Pankaj.
      I will try that too soon.
      Thanks a lot for your kind words

    • @codestorywithMIK
      @codestorywithMIK  Год назад

      Sure Pankaj.
      I will try that too soon.
      Thanks a lot for your kind words

  • @pradyumnmulegaon385
    @pradyumnmulegaon385 4 месяца назад +1

    i appreciate the depth of explanation that you have given in this video🔥🔥

  • @anubhavsingla3126
    @anubhavsingla3126 Год назад +1

    I tried this approach in my first attempt
    void solve(vector& nums, int index, vector& temp) {
    if(index == nums.size()) return;

    vector ans;
    for(int i=index; i

  • @udaytewary3809
    @udaytewary3809 Год назад +1

    You are awesome bhaiya I already solve the question using the map but your explanation comes like cherry 🍒 on top and by that my understanding towards the question increases to 10 times and for that really thankyou bhaiya really thankyou

  • @OtakRajCodes
    @OtakRajCodes Год назад +5

    wonderful explanation as always . Your method of first proving why the concept/technique works and then implementing it is awesome!! keep up the good work :)

  • @_jaydip74
    @_jaydip74 Год назад +5

    Hey Brother , I watch your videos daily and I just want to tell you that You are doing great work . Keep it up 🤗 .
    Love From Gujarat ❣.
    Thank you for the daily videos. 🙌

  • @shobhitsharma2137
    @shobhitsharma2137 9 месяцев назад +2

    Bro your explanation is so good that I can’t even imagine how you could have been able do this

  • @souravjoshi2293
    @souravjoshi2293 Год назад +3

    And the PERFECTION is here

  • @chaitanyakarthikbasva
    @chaitanyakarthikbasva Год назад +1

    Awesome explanation, and you were right, only you explained the root reason behind everything in the approach, huge love from south india

  • @ece39pranshupatel71
    @ece39pranshupatel71 4 месяца назад +2

    Thank you so much bhaiya..best explanation for modulo concept 💥❤️

  • @gui-codes
    @gui-codes 4 месяца назад +1

    Kya mast samjhate ho bhai. love you bhai
    Better than any video present on this problem on youtube

  • @nileshdeshmukh7841
    @nileshdeshmukh7841 Год назад +2

    Make daily videos bhaiya , it will help me to crack companies , my interview is scheduled and if I watch your video daily , i will definetly crack good companies , bcoz same I will going to explain in Interview starts from brute force to optimised. please keep uploading video daily !

  • @AnandKumar-kz3ls
    @AnandKumar-kz3ls Год назад +1

    the way you explain how to tackle with negative remainder is just awesome bro respect++

    • @zhunzargulhane6741
      @zhunzargulhane6741 10 месяцев назад

      what awesome yaar, how did he considered 7n-4 that is still not clear. Could you please explain from where this n is coming.

  • @abhishek_jha28
    @abhishek_jha28 Месяц назад +1

    Absolutely wow explanation

  • @Shivanai_h
    @Shivanai_h 11 месяцев назад +1

    Best explanation on youtube.. please keep uploading solution with awesome explanation like this:)

  • @raihanulalamhridoy4714
    @raihanulalamhridoy4714 Год назад +1

    A lot of effort was put into this video. Thank you for the explanation!

  • @venkatarohitpotnuru38
    @venkatarohitpotnuru38 4 месяца назад +2

    corner case is just lit🔥

  • @altafmazhar7762
    @altafmazhar7762 Год назад +2

    29:54 great job bro this is what we want

  • @mewaconite
    @mewaconite Год назад +1

    big respect for you brother, good explanation, quality video ! please continue your DSA series as well.

  • @dhairyachauhan6622
    @dhairyachauhan6622 Год назад +1

    A slightly better approach o(n2) whithout using prefix array
    the idea is to calculate the sum while building the subarrays
    class Solution {
    public:
    int subarraysDivByK(vector& nums, int k) {
    int n = nums.size();
    int ans = 0;
    for(int i = 0;i

  • @priyanshkumar17
    @priyanshkumar17 4 месяца назад +1

    Splendid Explanation Bhaiya !! Thanks & keep uploading such videos !! All the best to you😊😊😊😊🔥🔥

  • @deeparawat8308
    @deeparawat8308 Год назад +1

    Very nice and detailed approach✨
    Very helpful!
    Thank you👍

  • @Akashkumar_12
    @Akashkumar_12 4 месяца назад +2

    very good explanation thank you bhaiya

  • @Faiyaz__Ansari
    @Faiyaz__Ansari Год назад

    Amazing explanation of concepts step by step! Literally the best on RUclips!! 1M zyada door nahi

  • @rockykumarverma980
    @rockykumarverma980 Месяц назад +1

    Thank you so much Bhaiya ji 🙏🙏🙏

  • @atifhu
    @atifhu Год назад +2

    every time I am stuck in the ques, I know MIK is there for me❤🙌

  • @Sachin_Alam
    @Sachin_Alam Год назад +1

    Thanks a ton for the Cumulative sum approach.

  • @robot3.077
    @robot3.077 Месяц назад +1

    means remainder is
    (sum%k+k)%k
    for both positive and negative

  • @kalp2586
    @kalp2586 3 месяца назад +1

    Amazing explanation.

  • @thecricketerraja
    @thecricketerraja Год назад +1

    ur level of explanation 💥, tnku soo much bhai ❤

  • @tutuimam3381
    @tutuimam3381 Год назад +2

    Thanks a lot
    3 approaches 🔥🔥🔥

  • @utkarsh9233
    @utkarsh9233 Год назад +1

    wonderful explanation

  • @molyoxide8358
    @molyoxide8358 Год назад +2

    This line 29:53 shows your Patience level bro.

  • @shreyasharma7987
    @shreyasharma7987 4 месяца назад +1

    You explain so well!!! Thanks a lot.

  • @lokeshgoswami3748
    @lokeshgoswami3748 Год назад

    best teacher ,

  • @NatureLover-oq6uc
    @NatureLover-oq6uc Год назад +2

    Nice explanation sirji.....its a request plzz try to make videos little short....you would see a lot increase in no. of views on your channel.....btw thanks

  • @pritishpattnaik4674
    @pritishpattnaik4674 Год назад +1

    mein pehele try kiya aur n^2 solution hi likh paya then saw ur video , awesome explanation sir!!
    My Approach
    int subarraysDivByK(vector& nums, int k) {
    //O(n^2)
    int ans = 0;
    for (int i=0 ; i

    • @codestorywithMIK
      @codestorywithMIK  Год назад +1

      Thanks a lot Pritish.
      And I am so glad you tried O(n^2) on your own first. Way to go 💪💪💪

  • @divyasain15
    @divyasain15 4 месяца назад +1

    best explanation 🙌🙌

  • @nikhilhaspe2734
    @nikhilhaspe2734 4 месяца назад +1

    Hi Sir,
    Brute force will be of O(n^2) not O(n^3) as you said at 04:49
    Code:
    class Solution {
    public int subarraysDivByK(int[] nums, int k) {
    int sum, count=0;
    for(int i=0; i

  • @akmarkan2490
    @akmarkan2490 4 месяца назад +5

    Insane my brother⚔️⚔️🥵

  • @aftereffectstraining7668
    @aftereffectstraining7668 Год назад +1

    thank you! big fan of your explanation

  • @TUSHARJAIN-gv4fi
    @TUSHARJAIN-gv4fi Год назад +1

    Great Work

  • @AryanMishra-yh4ic
    @AryanMishra-yh4ic Год назад +1

    well explained

  • @kartikkk4583
    @kartikkk4583 Год назад +1

    best video bro dayum

  • @kumarsaurabh5449
    @kumarsaurabh5449 Год назад +1

    always waiting for you video .best teacher in yt..😀😀😀

  • @Music-tp8gg
    @Music-tp8gg Год назад

    Next level explanation

  • @nisargbarot1998
    @nisargbarot1998 Год назад +1

    Bhai superb explaination!!!

  • @amangoyal1600
    @amangoyal1600 8 месяцев назад +1

    Good Explained 😊

  • @jaygala6699
    @jaygala6699 Год назад +1

    great explanation!!! keep making these videos 👍👍

  • @piyushacharya7696
    @piyushacharya7696 Год назад +1

    this was my O(n^2) approach without prefix sum. Keep uploading. Nowadays if I get stuck I wait for your video to drop.
    class Solution {
    public:
    int subarraysDivByK(vector &nums, int k) {
    int n = nums.size();
    int ans = 0;
    int sum = 0;
    for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
    sum += nums[j];
    if (sum % k == 0) ans++;
    }
    sum = 0;
    }
    return ans;
    }
    };

    • @codestorywithMIK
      @codestorywithMIK  Год назад

      Awesome

    • @piyushacharya7696
      @piyushacharya7696 Год назад

      The O(n) approach is too hard to come up with.😅😅

    • @piyushacharya7696
      @piyushacharya7696 Год назад

      @@codestorywithMIK bro why you used map in the github code instead of unordered_map?

    • @codestorywithMIK
      @codestorywithMIK  Год назад

      That’s an old code. I will update it.
      Thanks for reminding Shrijal
      Let me update it now

    • @piyushacharya7696
      @piyushacharya7696 Год назад +1

      @@codestorywithMIK 🙌🙌

  • @_hulk748
    @_hulk748 Год назад +1

    Thankyou sir understood 🙇‍♂🙏❤

  • @santoshpathak8201
    @santoshpathak8201 9 месяцев назад +1

    Please Provide a Video on KMP and Z-Algorithm . We will be thankful

    • @codestorywithMIK
      @codestorywithMIK  9 месяцев назад

      KMP - ruclips.net/video/qases-9gOpk/видео.htmlsi=WDpG81RfsXWdXUX1

  • @tangududwarika4243
    @tangududwarika4243 Год назад +1

    Insane explanation just subscribed the channel

  • @JJ-tp2dd
    @JJ-tp2dd Год назад +1

    mza aa gya bhai..thanks

  • @yashgaur2470
    @yashgaur2470 Год назад +1

    Great Explanation sir!

  • @ispyu1514
    @ispyu1514 Год назад +1

    Great explanation!

  • @TechCraft5.O
    @TechCraft5.O Месяц назад +1

    wonderful!!!

  • @SatyamYadav-oz5ge
    @SatyamYadav-oz5ge 4 месяца назад

    bhaiya make videos on lc 401 and biweekly 132 (3rd and 4th one) dp

  • @Bankruptcoder786
    @Bankruptcoder786 6 месяцев назад +1

    thank you boss

  • @03_utpallucky40
    @03_utpallucky40 2 месяца назад +1

    iska mtlb jahan bhi subarray ki bat ho aur k diya ho divisible jaisa kch modulo baba ki jai ho soch skte .Crrct me if i am wrong.

  • @abhinay.k
    @abhinay.k Месяц назад +1

    thanks

  • @a3rdtierguy864
    @a3rdtierguy864 4 месяца назад +1

    Due to this negative remainder edge case i am unable to pass all testcases .

  • @shabananoor9423
    @shabananoor9423 Год назад +2

    3 ways 🔥🔥🔥

  • @letsgazestar
    @letsgazestar Год назад +1

    Hidden Gem .

  • @aizad786iqbal
    @aizad786iqbal 4 месяца назад

    cumaliive sum and prefix sum are same right ?
    btw there is a simpler brute force too..
    for(int i=0;i

  • @EB-ot8uu
    @EB-ot8uu 7 месяцев назад

    Best.

  • @niteshk0487
    @niteshk0487 Год назад +1

    mind blowing brdr👌✅

  • @karthikeysharma9161
    @karthikeysharma9161 Год назад +1

    🔥

  • @vaibhavjain709
    @vaibhavjain709 Год назад +1

    Good job man.

  • @aizad786iqbal
    @aizad786iqbal 4 месяца назад

    Hey MIK
    Longest subarray with sum divisible by K
    can u please make a video on this topic in your free time ..
    it should be based on similar logic right ?

  • @TusharRaja3009
    @TusharRaja3009 4 месяца назад

    maine brute force try kia, usme kewal 70 testcase pass hua and then tle aya. Can you make a video about what are importance of constraints.. and how to decide that as per constraint which which O() or bigOmega will be accepted... becoz i thought that 10^8 cycle per second is allowed , and in question we had Constraint that n is within 3x10^4... so i thought 10^4 ka square means 10^8 tak toh chalna chahiye tha means O(n square) chalna chahiya tha but nahi chala ... plzzz ispe video banao na..explaining these complexities(sorry for typos)

  • @mercenary06
    @mercenary06 Год назад +2

    Equivalent Java solution:
    class Solution {
    public int subarraysDivByK(int[] nums, int k) {

    int n = nums.length;
    int sum = 0, ans = 0;
    Map modMap = new HashMap();
    modMap.put(0, 1);
    for(int i = 0; i < n; i++){
    sum += nums[i];
    int rem = sum % k;
    if(rem < 0){
    rem += k;
    }

    if(modMap.containsKey(rem)){
    ans += modMap.get(rem);
    modMap.put(rem, modMap.get(rem)+1);
    }
    else{
    modMap.put(rem, 1);
    }
    }
    return ans;
    }
    }

  • @shashankvashishtha4454
    @shashankvashishtha4454 9 месяцев назад +1

    moj karadi sir.

  • @inglevivek8351
    @inglevivek8351 5 месяцев назад +1

    goat explanation

  • @curtdudeanmol9393
    @curtdudeanmol9393 Год назад +1

    your channel is going to grow , best of luck , well explained

  • @adhikari669
    @adhikari669 Год назад

    Bhaya ek vedio on all important algorithm for competitive 🙏🙏🙏 waiting for your vedio or a short ...

  • @hackingkingdom5634
    @hackingkingdom5634 4 месяца назад

    Op Explanation sir

  • @ravicharan6568
    @ravicharan6568 Год назад +1

    Thanks a lot!

  • @gauravbanerjee2898
    @gauravbanerjee2898 4 месяца назад

    Thank you so much bhaiya ❤❤