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

Поділитися
Вставка
  • Опубліковано 26 сер 2024

КОМЕНТАРІ • 191

  • @varunyadav6560
    @varunyadav6560 Рік тому +40

    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👍

  • @ramandeepsingh8464
    @ramandeepsingh8464 7 місяців тому +15

    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 🤩

  • @VivekPathak-ds2do
    @VivekPathak-ds2do 2 місяці тому +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 2 місяці тому +3

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

    • @Thriftinghai
      @Thriftinghai 2 місяці тому

      True

  • @tusharrajput983
    @tusharrajput983 2 місяці тому +2

    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.

  • @sourav-bisht
    @sourav-bisht Місяць тому +1

    No one explains like you bro
    You are the best

  • @LifeYetLive
    @LifeYetLive 26 днів тому +1

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

  • @adhikari669
    @adhikari669 Рік тому +3

    Bhaya aisa content pure UA-cam m khi ni h, na hi aisi awaj ❤️

  • @shobhitsharma2137
    @shobhitsharma2137 7 місяців тому +2

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

  • @rahulpandey5094
    @rahulpandey5094 11 місяців тому +3

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

    • @codestorywithMIK
      @codestorywithMIK  11 місяців тому

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

  • @himanshusharma9132
    @himanshusharma9132 2 місяці тому +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

  • @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 !

  • @akmarkan2490
    @akmarkan2490 2 місяці тому +5

    Insane my brother⚔️⚔️🥵

  • @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 💪

  • @tusharrajput983
    @tusharrajput983 2 місяці тому +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

  • @venkatarohitpotnuru38
    @venkatarohitpotnuru38 2 місяці тому +2

    corner case is just lit🔥

  • @atifhu
    @atifhu Рік тому +2

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

  • @_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. 🙌

  • @AbhayGupta-oz1ix
    @AbhayGupta-oz1ix Місяць тому

    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

  • @ece39pranshupatel71
    @ece39pranshupatel71 2 місяці тому +2

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

  • @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 :)

  • @yashika6248
    @yashika6248 Рік тому +1

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

  • @pradyumnmulegaon385
    @pradyumnmulegaon385 2 місяці тому +1

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

  • @itsaayush7357
    @itsaayush7357 8 місяців тому +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  8 місяців тому

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

  • @souravjoshi2293
    @souravjoshi2293 Рік тому +3

    And the PERFECTION is here

  • @gui-codes
    @gui-codes 2 місяці тому +1

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

  • @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

  • @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.

  • @AnandKumar-kz3ls
    @AnandKumar-kz3ls Рік тому +1

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

    • @zhunzargulhane6741
      @zhunzargulhane6741 8 місяців тому

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

  • @kalp2586
    @kalp2586 Місяць тому +1

    Amazing explanation.

  • @kumarimegha9187
    @kumarimegha9187 Рік тому +1

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

  • @user-fl1km1jq1d
    @user-fl1km1jq1d 10 місяців тому +1

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

  • @nagmakhan3165
    @nagmakhan3165 Рік тому +1

    The best explanation on UA-cam for this video

  • @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

  • @Shivanai_h
    @Shivanai_h 8 місяців тому +1

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

  • @thecricketerraja
    @thecricketerraja Рік тому +1

    ur level of explanation 💥, tnku soo much bhai ❤

  • @divyasain15
    @divyasain15 2 місяці тому +1

    best explanation 🙌🙌

  • @priyanshkumar_iitd
    @priyanshkumar_iitd 2 місяці тому +1

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

  • @Sachin_Alam
    @Sachin_Alam Рік тому +1

    Thanks a ton for the Cumulative sum approach.

  • @raihanulalamhridoy4714
    @raihanulalamhridoy4714 Рік тому +1

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

  • @nikhilhaspe2734
    @nikhilhaspe2734 2 місяці тому +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

  • @jaygala6699
    @jaygala6699 Рік тому +1

    great explanation!!! keep making these videos 👍👍

  • @mewaconite
    @mewaconite Рік тому +1

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

  • @amangoyal1600
    @amangoyal1600 6 місяців тому +1

    Good Explained 😊

  • @tutuimam3381
    @tutuimam3381 Рік тому +2

    Thanks a lot
    3 approaches 🔥🔥🔥

  • @dhairyachauhan6622
    @dhairyachauhan6622 11 місяців тому +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

  • @altafmazhar7762
    @altafmazhar7762 Рік тому +2

    29:54 great job bro this is what we want

  • @curtdudeanmol9393
    @curtdudeanmol9393 Рік тому +1

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

  • @niteshk0487
    @niteshk0487 Рік тому +1

    mind blowing brdr👌✅

  • @tangududwarika4243
    @tangududwarika4243 11 місяців тому +1

    Insane explanation just subscribed the channel

  • @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

  • @kartikkk4583
    @kartikkk4583 Рік тому +1

    best video bro dayum

  • @Faiyaz__Ansari
    @Faiyaz__Ansari 11 місяців тому

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

  • @Music-tp8gg
    @Music-tp8gg Рік тому

    Next level explanation

  • @utkarsh9233
    @utkarsh9233 11 місяців тому +1

    wonderful explanation

  • @deeparawat8308
    @deeparawat8308 Рік тому +1

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

  • @Akashkumar_12
    @Akashkumar_12 2 місяці тому +2

    very good explanation thank you bhaiya

  • @yashgaur2470
    @yashgaur2470 Рік тому +1

    Great Explanation sir!

  • @03_utpallucky40
    @03_utpallucky40 13 днів тому +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.

  • @shreyasharma7987
    @shreyasharma7987 2 місяці тому +1

    You explain so well!!! Thanks a lot.

  • @kumarsaurabh5449
    @kumarsaurabh5449 Рік тому +1

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

  • @lokeshgoswami3748
    @lokeshgoswami3748 Рік тому

    best teacher ,

  • @_hulk748
    @_hulk748 Рік тому +1

    Thankyou sir understood 🙇‍♂🙏❤

  • @santoshpathak8201
    @santoshpathak8201 7 місяців тому +1

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

    • @codestorywithMIK
      @codestorywithMIK  7 місяців тому

      KMP - ua-cam.com/video/qases-9gOpk/v-deo.htmlsi=WDpG81RfsXWdXUX1

  • @a3rdtierguy864
    @a3rdtierguy864 2 місяці тому +1

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

  • @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

  • @nisargbarot1998
    @nisargbarot1998 Рік тому +1

    Bhai superb explaination!!!

  • @aftereffectstraining7668
    @aftereffectstraining7668 Рік тому +1

    thank you! big fan of your explanation

  • @shabananoor9423
    @shabananoor9423 Рік тому +2

    3 ways 🔥🔥🔥

  • @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 💪💪💪

  • @TUSHARJAIN-gv4fi
    @TUSHARJAIN-gv4fi Рік тому +1

    Great Work

  • @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;
    }
    };

  • @inglevivek8351
    @inglevivek8351 3 місяці тому +1

    goat explanation

  • @shashankvashishtha4454
    @shashankvashishtha4454 6 місяців тому +1

    moj karadi sir.

  • @Bankruptcoder786
    @Bankruptcoder786 4 місяці тому +1

    thank you boss

  • @kratimishra2283
    @kratimishra2283 Рік тому +1

    Hidden Gem .

  • @SatyamYadav-oz5ge
    @SatyamYadav-oz5ge 2 місяці тому

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

  • @ispyu1514
    @ispyu1514 Рік тому +1

    Great explanation!

  • @molyoxide8358
    @molyoxide8358 Рік тому +2

    This line 29:53 shows your Patience level bro.

  • @hackingkingdom5634
    @hackingkingdom5634 2 місяці тому

    Op Explanation sir

  • @gauravbanerjee2898
    @gauravbanerjee2898 2 місяці тому

    Thank you so much bhaiya ❤❤

  • @user-ub2is4rs4x
    @user-ub2is4rs4x 2 місяці тому

    Mast ❤

  • @aws_handles
    @aws_handles 5 місяців тому

    This is lit 👌🏻👌🏻👌🏻

  • @JJ-tp2dd
    @JJ-tp2dd Рік тому +1

    mza aa gya bhai..thanks

  • @TusharRaja3009
    @TusharRaja3009 2 місяці тому

    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)

  • @saurabhsagar3134
    @saurabhsagar3134 Рік тому +1

    OP brother

  • @adhikari669
    @adhikari669 Рік тому

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

  • @ravicharan6568
    @ravicharan6568 11 місяців тому +1

    Thanks a lot!

  • @AryanMishra-yh4ic
    @AryanMishra-yh4ic Рік тому +1

    well explained

  • @dibbodas4116
    @dibbodas4116 2 місяці тому

    if remainder is negative why we adding k rather than any number? modulo + k wala part hard hea

  • @aizad786iqbal
    @aizad786iqbal 2 місяці тому

    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 ?

  • @karthikeysharma9161
    @karthikeysharma9161 Рік тому +1

    🔥

  • @kalp2586
    @kalp2586 Місяць тому +1

    Thanks!

  • @a3rdtierguy864
    @a3rdtierguy864 2 місяці тому +1

    BHaiya please provide solution of leetcode contest 3181 solution please

  • @EB-ot8uu
    @EB-ot8uu 5 місяців тому

    Best.

  • @vagabondfoodie5788
    @vagabondfoodie5788 2 місяці тому

    sir, i have a question , what if remainder is not present in the map????
    i know we have to push it into the map right.....
    but in the code we have not even pushed it, then how it is working??????

  • @AyushSingh-hc3pj
    @AyushSingh-hc3pj 2 місяці тому

    at 18:26 5 divide by 7 5 kaise aa raha hai and same goes for 2 divide by 7 2 kaise aa raha hai

  • @vaibhavjain709
    @vaibhavjain709 Рік тому +1

    Good job man.

  • @Thriftinghai
    @Thriftinghai 2 місяці тому

    Thanks a lot