3Sum | LeetCode 15 | C++, Java, Python

Поделиться
HTML-код
  • Опубликовано: 19 окт 2024
  • LeetCode Solutions: • LeetCode Solutions | L...
    Data Structures and Algorithms playlist: • Data Structures and Al...
    Github Link: github.com/Kno...
    *** Best Books For Data Structures & Algorithms for Interviews:*********
    1. Cracking the Coding Interview: amzn.to/2WeO3eO
    2. Cracking the Coding Interview Paperback: amzn.to/3aSSe3Q
    3. Coding Interview Questions - Narasimha Karumanchi: amzn.to/3cYqjkV
    4. Data Structures and Algorithms Made Easy - N. Karumanchi: amzn.to/2U8FrDt
    5. Data Structures & Algorithms made Easy in Java - N. Karumanchi: amzn.to/2U0qZgY
    6. Introduction to Algorithms - CLR - Cormen, Leiserson, Rivest: amzn.to/2Wdp8rZ
    *****************************************************************************
    July LeetCoding Challenge | Problem 8 | 3Sum | 8 July,
    Facebook Coding Interview question,
    google coding interview question,
    leetcode,
    3Sum,
    3Sum c++,
    3Sum Java,
    3Sum python,
    3Sum solution,
    15. 3Sum,
    #CodingInterview #LeetCode #JulyLeetCodingChallenge #Google #Amazon #3Sum

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

  • @HKabir360
    @HKabir360 2 года назад +1

    Clear explanation, Thanks

  • @bittupandey6645
    @bittupandey6645 2 года назад +2

    I always look for your explanation it is crisp and clear !!

  • @somyasrivastava6315
    @somyasrivastava6315 3 года назад +1

    One word for this... beautiful

  • @Mr.Starmaker
    @Mr.Starmaker 4 года назад +3

    Amazing !! Loved this Time order and code together thank you

  • @AbhishekKumar-eh6zy
    @AbhishekKumar-eh6zy 3 года назад +1

    air your explanation is the best

  • @267praveen
    @267praveen 3 года назад +1

    Hi
    Won' t the logic you explained for 2-SUM change the indices post sorting? In order to use the left-right logic, we need to sort the array. Once sorted, the indices will get updated. So the i and j will reflect indices of sorted array not the original array.
    Can you please clarify?

  • @jlo4033
    @jlo4033 3 года назад +2

    Thanks a lot! helps me figur out how to code it.

  • @mukultaneja7243
    @mukultaneja7243 4 года назад +2

    2 pointer approach is awesome. But sir can we do it with DP...? I spent 3 hours in it....I even took 4D DP array but but didn't get correct solution. It was easily done with the help of (coin change) recursion.

  • @emanejaz1501
    @emanejaz1501 3 года назад +2

    Thankyou for the effort. You explained it really well.

  • @shaantyagi2187
    @shaantyagi2187 2 года назад +1

    Thanks

  • @AshishRawat-zl6te
    @AshishRawat-zl6te 3 года назад +2

    Great explanation!!!

  • @GauravSingh-ku5xy
    @GauravSingh-ku5xy 2 года назад +1

    very well explained.

  • @rishisharma5249
    @rishisharma5249 4 года назад +2

    Awesome video sir!!!
    Keep posting them

    • @KnowledgeCenter
      @KnowledgeCenter  4 года назад

      Thank you

    • @rishisharma5249
      @rishisharma5249 4 года назад

      @@KnowledgeCenter Your Welcome sir!!!
      Hope your channel reaches to 100K soon!

  • @senthilkumar5
    @senthilkumar5 3 года назад

    Thank you so much for a simpler solution!!!

  • @adarshmv261
    @adarshmv261 4 года назад

    Just one doubt: In python code - Line 17 - i had written 'if' instead of 'elif' and one tc was failing. What diff it will make?
    because all 3 conditions are different right i.e summ == 0, summ < 0 and summ > 0 so anyway only either of these should execute. (btw we've to use summ not sum as var name - bcoz sum is keyword in python)

  • @crankyinmv
    @crankyinmv 4 года назад +1

    Thanks, This is the strategy I used as well, though I couldn't do better than 43% on the time. Maybe because I did the 2sum part as a separate function and in JS.
    Anyhoo, here's a possible optimization (right after line 9 in the C++ code):
    if(nums[i] > 0) break;
    ehilr

  • @anushsharma8645
    @anushsharma8645 4 года назад +2

    just awesome

  • @kushaalrana
    @kushaalrana 4 года назад +1

    Thank you well explained👍 and we'll coded too I didn't knew the use of this -> {} operator in vector but now I do. Thanks to you👌

  • @SR-we1vl
    @SR-we1vl 4 года назад +2

    Keep up the good work!

  • @vinaykaranam5957
    @vinaykaranam5957 3 года назад +1

    Brilliant!

  • @anishsuman1371
    @anishsuman1371 3 года назад

    Gajab search for one element in sorted array takes logn time

  • @naidusunny2744
    @naidusunny2744 4 года назад +1

    while(j < k && nums[j] == nums[j+1]) j++;
    while(j < k && nums[k] == nums[k-1]) k--;
    Can someone explain me what is the use these 2 while loops?

    • @abdelrahmannour1249
      @abdelrahmannour1249 4 года назад +3

      It's just like mentioned in the solution. He made the two while loops to avoid duplicate solutions for the fixed first number. So , he incremented the (j) pointer if the next element in the sorted array is equal to the the current one (which will lead to the same current solution) and the same goes for the (k) pointer but with decrementing.

  • @anandmishra8060
    @anandmishra8060 4 года назад

    2 while condition we are checking for sum==0.... We could check these conditions for sum>0 and sum

    • @mukultaneja7243
      @mukultaneja7243 4 года назад

      If(sum == 0) means nums[j] + nums[k] = 0. So here we have to make sure that one of these or both numbers do not repeat, as we will get duplicate answer in that, but........other if conditions do not require these while conditions as it's working the same without them.

  • @paragroy5359
    @paragroy5359 3 года назад

    Nice explanation sir.......

    • @KnowledgeCenter
      @KnowledgeCenter  3 года назад

      Thanks for liking

    • @paragroy5359
      @paragroy5359 3 года назад +1

      @@KnowledgeCenter Please keep on making videos on leetcode problems this is really helpful sir....

  • @pratyushranjansahu9495
    @pratyushranjansahu9495 4 года назад

    Thanks for the explanation. Always i skip the problem..Now always i have to attain... :)

  • @aminesfahani3563
    @aminesfahani3563 3 года назад

    thanks alot

  • @KomalPal
    @KomalPal 4 года назад +1

    How could i reach u, either give yours Instagram handle or linkedin profile