3 SUM - (Amazon, Meta, Google) : Explanation ➕ Live Coding 🧑🏻‍💻👩🏻‍💻

Поділитися
Вставка
  • Опубліковано 9 січ 2025

КОМЕНТАРІ • 81

  • @password47403
    @password47403 Рік тому +29

    Wanted to see your approach to this problem...literally the best solution for the 3-Sum problem present on UA-cam!
    Kudos!

  • @coolsai
    @coolsai 13 днів тому +3

    Kuch aur search kiya tha kuch aur aagaya but dekhne ke baad ye bhi intresting lag raha hai.

  • @shikharai-tl4vb
    @shikharai-tl4vb Місяць тому +2

    Share this channel with anyone who needs genuine help with building strong logic. As a working professional, I regret not finding this channel earlier in my journey, but better late than never! With 3 years of experience, I still find it incredibly valuable. Thanks, MIK!

  • @amararbat9639
    @amararbat9639 8 місяців тому +7

    I'm glad I found you during my DSA journey. Thanks for everything!

  • @shashankshandilya1517
    @shashankshandilya1517 2 роки тому +2

    This is by far the best solution i have seen on You tube Thank you for explaining Medium level ka question lga hi nhi aapke explanation k wjh se thank you Highly Appreciate your efforts

  • @xiaoshen194
    @xiaoshen194 Рік тому +6

    3 sum is ❤️. Got to learn a lot from it.

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

    Hello mik sir, you r helping me to understand dsa concepts, thank you so much sir, god bless you❤

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

    Bhaiya apke itne ache explanation ki wajah se 4SUM wala khud kar diya maine
    Thank you bhaiya🥰

  • @ashwin_anand_dev
    @ashwin_anand_dev 7 днів тому

    Thank you bhaiya for explaining the approach so deeply. I have one question regarding the input array below:
    -4, -1, -1, 0, 0, 1, 2, 2
    In this in the first step we assume that the n1 is -4 and -n1 will be -(-4) or 4. Now we need to find number n2 and n3 which adds up to 4.
    Starting from i at 1 and j at 7, we first increment the i as value at i + 1 is same as value at i and similarly we decrement the j as value at j - 1 is equal to value at j.
    After that we continue wit this approach and updating the variables i and j until they cross. My question is that {-4, 2, 2} can be one of the elements of the output array. I mean it clearly is as the triplet sum is 0, but following the approach for this as briefly discussed above, value at i will never reach the value 2 in this case.
    Could you or anyone please explain if I missed something here?

  • @NitinSingh-tu7bm
    @NitinSingh-tu7bm Рік тому +3

    seriously i got so much help because of you to how to think for code and urs approaches are very awesome thanks for giving me such type of knowledge

  • @rv5778
    @rv5778 9 місяців тому +2

    Was not able to solve and understand intuitions of solutions available already Today and Felt very low .
    Hands down to best solution 🙏

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

    This was the best approach for this problem. Thanks for this explanation! Such a great channel.

  • @arambh-gaur
    @arambh-gaur 3 місяці тому +1

    Bhai !! what an explaination ! fantastic

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

    Assalamualaikum Brother,
    Dil se Salam hai aise Explaination aur Explain karne wale pe ❤

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

      Walaikum Assalam Bari.
      Thank you so much for your precious comment ❤️❤️❤️

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

    sir , i don't have words to say thankyou for all the videos you have uploaded , you are really a gem trust me

  • @MohammedHasmi577
    @MohammedHasmi577 14 днів тому

    Greatest explanation ❤🔥

  • @BalkrishnaPatki
    @BalkrishnaPatki 10 місяців тому +1

    thank you bhaiii ,thank you soo much for your all efforts

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

    The way u explain each question feels like every dsa question is just a cupcake 😭😭

  • @AkashKumar62000
    @AkashKumar62000 3 місяці тому

    really.. u r too good sir.. hats off

  • @harsh.jain22
    @harsh.jain22 Рік тому +2

    👌great stuff

  • @rohitrajput2097
    @rohitrajput2097 9 місяців тому +1

    Bro you solved my problem.Thanks

  • @ManasNandMohan
    @ManasNandMohan 10 місяців тому

    You point all the valuable , plese make more playlist ,you are op

  • @opsahadat9567
    @opsahadat9567 10 місяців тому

    Just Awesome.

  • @zaviyakhurshid9097
    @zaviyakhurshid9097 2 роки тому +1

    Amazing Explanation💫

  • @ManasNandMohan
    @ManasNandMohan 10 місяців тому

    u don't make it just easy U make us also believe on it

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

    Thanks a lot bhaiya ❤❤

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

    nice i dont usually comment but hats off

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

    bhaiiii mn maan gae hu apko , APKO GOOGLE KA CEO HONA CHAHYE

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

    bhayia ek baat batayie 18:40 mein aapne 2 2 times kyu considerd kiya apne
    apke logic ke hissab se 2 to skip ho jana chaiye the because j == j -1.
    Answer {-4, 2,2} kasie?

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

      For those who are having same doubt :
      This doubt got cleared through code.
      we will increment - decrement i and j based on their duplicacy only if i th + j th element provides us the target element.
      as it was the root of why increment/decrement coz we were getting answer and if not skipped we will again get same answers again.
      hence even in (0,0,0) example we get the expected answer.

  • @KishanSingh-vc3re
    @KishanSingh-vc3re 6 місяців тому +1

    while fixing a particular number why dont we consider the umber on left side

  • @queenshijain3089
    @queenshijain3089 13 днів тому

    please upload the solution video of find triplets of zero sum

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

    Understood

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

    underrated playlist hai

  • @adarshsrivastava3657
    @adarshsrivastava3657 Рік тому +8

    why only 12.3K sub..??

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

      Hi @adarshsrivastava3657,
      ***Let me share my long observation.***
      I also had the same Qn when I started following this channel. I noticed that this guy never ever asked or forced to subscribe in any of his video. Other UA-camrs almost mention this in their every video but this guy is unique. May be that's why he is not famous till now. I once shared his channel to two of my friends in college and now whole college (CS & IT) knows this guy as MIK and everyone literally watches his channel.
      In one of his videos, he also mentioned he rejected some offers from some Paid Platform (he didn't mention the company name) to advertise their platform in his videos.
      This caught my attention on how different mik is. I was a big fan of striver and love Babbar but even they also promote paid platforms which I don't think are good enough and only charge fees to sell their course etc. This is what I found from his GitHub repository - "Why I am doing this ? Because knowledge should be free. You don't need to pay for courses. Learn free, share free. PEACE 💓"
      The respect for this guy increased more and more with time and I became a big fan of this legend.
      People might ask why I have written such a long reply to this comment - My answer is because generally we don't see our unsung heroes and in this case, it's this legend MIK who is doing everything for free.

    • @swagboltey102
      @swagboltey102 10 місяців тому +2

      Literally Mai bhi itna acha ye samjane ke baad deko to he deserves more

    • @Lakshya-f4l
      @Lakshya-f4l 6 місяців тому +1

      55.7K now

    • @phanitejakv
      @phanitejakv 5 місяців тому +1

      58.4K now

    • @sksadiruddin4191
      @sksadiruddin4191 Місяць тому

      74.5K now

  • @Daksh-dz7hk
    @Daksh-dz7hk 6 місяців тому

    Awsm video🤓
    Can you please tell the time complexity?

  • @jdjkjffdal
    @jdjkjffdal 9 місяців тому +1

    sei sei

  • @theonly_ashu
    @theonly_ashu 3 місяці тому

    12:24

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

    Gem ❤

  • @bhanupratapjaiswal4741
    @bhanupratapjaiswal4741 21 день тому

    Hello , can someone solve my doubt how we will get {-4 ,2 , 2 } as answer because if(arr [ j ] = = arr [ j - 1 ] ) we do j - - . So how we can get 2 + 2 , and also i < j . Can someone help me?

  • @kalyanraj-qr5ke
    @kalyanraj-qr5ke 2 місяці тому

    Bhai, ap konsa software use karthe hoo, drawing keliye

  • @khirodrout6357
    @khirodrout6357 9 місяців тому

    if the array is not sorted , then how to remove duplicates in this case?

  • @ManasNandMohan
    @ManasNandMohan 10 місяців тому

    Please also add tc & sc on it

  • @parkInSuns
    @parkInSuns 2 роки тому +1

    Hey! Awesome explanation as always, btw I was wondering why did you use begin(nums) rather than nums.begin(), I was coding the algorithm by myself, I used nums.begin(), now I had to push to the vector before the repetition checks in the two sum function, I googled it, but didn't get any sure answers from SO too. Any Idea?

    • @codestorywithMIK
      @codestorywithMIK  2 роки тому +2

      Hi Ausaf.
      Both are same.
      begin(nums)
      nums.begin()
      I just usually use both of them interchangeably just for my practice and knowledge 🙂
      Hope that answers your qns.
      Is there any other doubt that I couldn’t clear ?
      Kindly let me know.
      Thanks for watching ❤️❤️❤️

    • @parkInSuns
      @parkInSuns 2 роки тому

      @@codestorywithMIK ohk, the explanation was on point as always. 😊

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

    Why was result array cleared 🤔 @29:39

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

      Bhai clear nahi karoge to bhi chalega it still works.

    • @Shantanu_Jod
      @Shantanu_Jod 6 місяців тому

      Wahi mai bhi soch rha tha bhai

  • @priyajaiwal8072
    @priyajaiwal8072 9 місяців тому +1

    The way you pointed out why we need to see if n1 is repeated (considered already) and why same logic will apply in repeating i and j when finding n2,n3 is 🤌🏻

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

    bhaiya yha pe to smjh aa jata hai interview mein yd hi ni rhta

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

    bhaiya will you please tell me why we are looking for n2 and n3 in the arr after n1, because it might happen that n2 or n3 can lie before n1 (fixed) also.

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

      He told us that first element will be n1....so how can n2 and n3 lie before n1

  • @AnkitJain-w3l
    @AnkitJain-w3l 10 місяців тому

    Day -1

  • @mayank1522
    @mayank1522 5 місяців тому +1

    why did u cleared the result sir?
    \

  • @Shashwat-000
    @Shashwat-000 7 місяців тому +1

    why dont we use hashset for duplication?

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

      No use of extra space already mentioned

    • @Shashwat-000
      @Shashwat-000 4 місяці тому

      @@ankitankit3391 Hmmm,Thanks

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

    java version please?actually in java some test cases failed from my side

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

    Java solution please

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

    Java Solution below:
    package week7.day43;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.List;
    public class ThreeSum {
    public static void main(String[] args) {
    int[] nums = {-4, -2, 1, -5, -4, -4, 4, -2, 0, 4, 0, -2, 3, 1, -5, 0};
    List lists = threeSum(nums);
    System.out.println(lists);
    }
    private static List threeSum(int[] nums) {
    int n = nums.length;
    List list = new ArrayList();
    int target = Integer.MAX_VALUE;
    if (n < 3)
    return list;
    Arrays.sort(nums);
    for (int x = 0; x < n; x++) {
    if (target == -(nums[x]))
    continue;
    target = -(nums[x]);
    int i = x + 1;
    int j = n - 1;
    while (i < j) {
    List l = new ArrayList();
    int sum = nums[i] + nums[j];
    if (sum > target)
    j--;
    else if (sum < target) {
    i++;
    } else {
    while (i < j && nums[i] == nums[i + 1])
    i++;
    while (i < j && nums[j] == nums[j - 1])
    j--;
    list.add(Arrays.asList(nums[x], nums[i], nums[j]));
    i++;
    j--;
    }
    }
    }
    return list;
    }
    }

  • @souravgorai9481
    @souravgorai9481 10 місяців тому

    Bhaiya abhi ek naya edge case add hua hai - input is [0,0,0]. Isme problem ye ho rhi hai ki because all elements are same sab kuch skip ho ja rha.

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

      Hey,
      No it won’t be skipped .
      The expected output is {{0,0,0}}
      The code will give this output.

    • @souravgorai9481
      @souravgorai9481 10 місяців тому

      @@codestorywithMIK Yes I figured that out later. Thanks !

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

    legit