Two Sum (LeetCode #1) | 3 Solutions with animations | Study Algorithms

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

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

  • @nikoo28
    @nikoo28  3 года назад +52

    At 12:58, I am supposed to add "8" to the hash table and not "11".
    Sorry for the error.

    • @atharvalaad8926
      @atharvalaad8926 3 месяца назад

      😅😅😅😅😅😅😅 15:52 😅😅😊😅😅😅 15:52 15:52 15:52 15:52 15:52 😅 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 😅 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 😅 15:52 15:52 15:52 15:52 15:52 15:52 15:52

  • @halimaomar9820
    @halimaomar9820 2 года назад +49

    This is absolutely the best explanation on RUclips. Everyone else goes straight to coding and doesn't break down the logic beforehand.

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

      Happy that I could help :)

  • @billyfigueroa1617
    @billyfigueroa1617 9 месяцев назад +4

    Excellent content. This is the second video I watch which allows one to be able to devise a nicer solution simply by sorting the array. The hash map solution is genius and is not complicated
    I will now, always look at a problem and find out how I can solve it by first thinking "Would sorting this array help to simplify the solution"

  • @AKASH-fe6vy
    @AKASH-fe6vy 2 месяца назад +1

    So nice of you to put this in a simple yet insightful manner, thanks a lot.

  • @jst8922
    @jst8922 11 месяцев назад

    06:03 - Method 1: Using Sorting
    This is basically sliding window solution, when you have two pointers , left and right and you move them correspondingly.

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

    Good video, very similar to my university lectures.
    I think the reason a lot of people fail to learn some things on their own is that they just see code and want to understand it magically, you need to get the logic behind stuff.

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

    Underrated channel.

  • @Rockstar-16
    @Rockstar-16 2 года назад +3

    Sir😄, I have no words, I have never seen anyone explain this nicley, thank you so much❤

    • @nikoo28
      @nikoo28  2 года назад

      Thank you so much for your kind words.

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

    you r really an excellent teacher one thing i want to tell ur explanation is better that striver thanks for providing such videos

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

    thank you soooo much! I checked out so many videos about this question. finally your video helped me out! firmly subscribed to your channel

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

    Such a great way of explaining this problem. You have redefined teaching sir!!! Amazing Work!!!!

  • @ayushtalks2.0
    @ayushtalks2.0 2 года назад +8

    One of the best way of teaching . Sir Keep posting more videos of dsa. 👍👍

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

      Thank you so much for your support :)

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

    I watched two other videos before coming here , to be honest you are the best one . I only understand from you because other people talk too long without explaining they talk about the problem not the solution. You even taught me the math side of this . Thank you , I subscribed. I will watch the rest of the solutions

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

      I prefer to focus on the problem. Language is a tool anyway, and they will keep changing and evolving. Thanks for the sub!!

  • @pooja3711
    @pooja3711 11 месяцев назад

    you are the best.I really appreciate your hard work and step-by-step approach to how to overcome with a solution. Hats off

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

      thanks for the appreciation and motivation :)

  • @elizabeth00653
    @elizabeth00653 6 месяцев назад

    Thank you for taking the time to create this video and make a clear explanation

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

    Only just got into coding a few days ago coming from a teacher background. Great explanations!

  • @Karan-ow4wl
    @Karan-ow4wl 2 месяца назад

    Best Video Explanation so far !!!

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

    I was searching for the solution but do not found dryryn but u did it thank bro ❤️

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

    Love the way you teach, TYSM☺

  • @sarthakgadge5223
    @sarthakgadge5223 5 месяцев назад

    Thanks a lot, I was able to understand this problem thanks to your efforts.

  • @shacks-b3b
    @shacks-b3b 10 месяцев назад

    Please keep uploading DSA/leetcode videos, they all are really helpful, thanks!

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

      More to come!

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

    You're by far the most detailed explainer I've seen. I've seen a few, but you're really amazing. Having a coding interview soon.

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

      All the very best for your upcoming interviews :)

  • @RajKumar-li8dc
    @RajKumar-li8dc Год назад +1

    Best way to teach sir plz discuss more question and make a proper playlist ❤❤❤

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

      Check out my playlists in the channel :)

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

    your explanation is for more better than other youtuber

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

      Glad you feel that way :D

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

    Thank you bro you do grate things
    your explanation is very simple and easy to understand
    Iam so happy to see this video

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

      so happy to read this

  • @kishanbhadoriya8701
    @kishanbhadoriya8701 11 месяцев назад

    Thank you very much, finally understood

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

    Best explanation 👌

  • @japaneseger
    @japaneseger 2 года назад

    You explained it very well, best video out there regarding this solution!!"!!!!

  • @TV-wk7oo
    @TV-wk7oo Год назад

    Thank you, you are the best! Visualizing the code helped me a lot

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

    Good one

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

    Thank you ❤

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

    Thank you for the video it really helped me!

  • @AkaNuclear
    @AkaNuclear 7 месяцев назад

    For the second solution where we are using hashmap, the time complexity of finding an element is also O(n) in case of hash collisions

    • @nikoo28
      @nikoo28  7 месяцев назад

      For a very big input size, yes there will be collisions…but for the domain of this problem you should be just fine.
      Good to discuss this with your interviewer though 😄

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

    Amazing

  • @dineshpatil6698
    @dineshpatil6698 2 года назад

    such clear explantion , subscribed

  • @pulastyadas3351
    @pulastyadas3351 2 года назад

    awesome explanation..keep teaching us

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

    Very smooth sir

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

    sir @nikoo28 ,there is a mistake in two pointer approch i think where if => num1 and num2 are the same (e.g., nums = [3,3], target = 6), so code will return the same index for both numbers, especially if there are duplicates in the original array. for ex nums =
    [3,3]
    target =
    6
    Output
    [1,1]
    Expected
    [0,1] which is wrong so should we apply something else here?

    • @matthewzarate8851
      @matthewzarate8851 Месяц назад

      I had a similar issue with this test case as well.
      The way I fixed it is I made sure I was only inserting a {key:value} pair into my hashMap (example: target - nums[index]) at the end of the for-loop. I evaluate if condition ( map.containsKey(target - nums[index]) ) first, if not satisfied then I insert this new {key:value} pair into my hashMap and continue on with the next iteration of the for-loop. This generalizes the solution to fix the [3,3] target = 6 case.
      Also I haven't tested Nikhil's solution but it looks correct to me.

    • @coldcases_2
      @coldcases_2 Месяц назад

      @@matthewzarate8851 i was talking about two pointer approch there is mistake in two pointer approch i already give example in my comment

    • @matthewzarate8851
      @matthewzarate8851 Месяц назад

      @@coldcases_2 There isn't a mistake in the two pointer approach. You need to add complexity for the case when i = j, that takes care of this special case.

    • @matthewzarate8851
      @matthewzarate8851 Месяц назад

      @@coldcases_2 when doing the brute force method you can fix this condition by
      for () {
      for() {
      if (target == nums[I] + nums[J]) && I != J then return (I,J);
      }
      }
      This takes care of all test cases. We added some complexity in the if condition.

  • @AbhishekRamola-u7y
    @AbhishekRamola-u7y 5 месяцев назад

    Kudos! Great explanation brother.P.s: Bro, you sound exactly like Pennywise from It.

  • @sanjeewagunarathna1990
    @sanjeewagunarathna1990 2 года назад

    Great video best explanation

  • @04.nehalsingh12
    @04.nehalsingh12 2 года назад

    awesome tutorial sir

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

    awesome video... keep making them

  • @TanviTiwari-lu6sf
    @TanviTiwari-lu6sf Месяц назад

    I caan easily understand this code

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

    I had a question about the tastable, 19-4 is 15, but it is on the table so why don't we stop there? Thank you

  • @kunalkheeva
    @kunalkheeva 2 года назад

    thank you for a great explanation, what would be its space complexity?

    • @nikoo28
      @nikoo28  2 года назад

      Which solution do you want the space complexity for? :)

  • @dipanwitasahoo6643
    @dipanwitasahoo6643 8 месяцев назад

    Is this possible using binary search?

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

    Best

  • @sunnyrajesh
    @sunnyrajesh 7 месяцев назад

    Hello I have a small doubt ? How we return two index values here map.get(complement),i);
    Can any one explain 🤔 does it return complement index and current I value ?

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

    Hi Nikhil, what program do you use to draw the solution?

    • @nikoo28
      @nikoo28  11 месяцев назад

      GoodNotes 6

  • @lipovgaming7245
    @lipovgaming7245 3 месяца назад

    but how do you return 2 elements.

  • @Programming-for-all-u2l
    @Programming-for-all-u2l 10 месяцев назад +1

    I do not know why he gets very few likes and he is the best teacher for explaining the leetcode problems

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

      so happy you believe in me. Please share the videos if possible. Trying my best with SEO to get ranked up in search results.

    • @ashishsonii
      @ashishsonii 3 месяца назад

      Brother don't stop making leetcode questions​@@nikoo28

  • @sushant3530
    @sushant3530 2 года назад

    Sir will 3rd Method will work if array has Duplicate elements . Becoz in HashMap , the key cannot be duplicate. And if array elements repeats , they duplicate key is found. PLZZZZ PLZZ EXPLIAN THIS SIR

    • @nikoo28
      @nikoo28  2 года назад

      since the problem says you will have EXACTLY ONE SOLUTION, you do not need to worry about duplicate number. Because if a duplicate number exists, then you will have 2 possible solutions...and hence that is not a valid scenario.

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

      @@nikoo28 but in the example there is repetitive element

    • @RapJunkie
      @RapJunkie 5 месяцев назад

      @@nikoo28 we have a valid scenario [3,3], and this method won't work :(

  • @karthik-varma-1579
    @karthik-varma-1579 8 месяцев назад

    AT 10:31 the method is not working for negative numbers in the array;

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

      the optimized method takes care of all different test cases

    • @karthik-varma-1579
      @karthik-varma-1579 8 месяцев назад

      @@nikoo28 Ohk Thanks Sir

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

    what is this """'' return new int[]{map.get(complement),i}; """" ? as it throws error and i am getting you've used curly brackets with new int[]...................please reply..........................

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

      It gets the complement pair and then returns it as an array.

  • @ME022GopinathanAsokan
    @ME022GopinathanAsokan 11 месяцев назад

    sir
    what language you are used here

  • @kashmirviews4332
    @kashmirviews4332 7 месяцев назад

    Can anybody tell how to write the main function code for the same function.

    • @nikoo28
      @nikoo28  7 месяцев назад +1

      Just create an object of the class and call it in the main method

    • @kashmirviews4332
      @kashmirviews4332 7 месяцев назад

      @@nikoo28 thanks.

  • @ymhuang651
    @ymhuang651 2 года назад

    Awesome channel! Why I Find it so late?

    • @nikoo28
      @nikoo28  2 года назад

      Glad I could help you 😄

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

    subbed!

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

    its cool

  • @shubhi1396
    @shubhi1396 2 месяца назад

    Why new is written in return

  • @ssss22144
    @ssss22144 Месяц назад

    🎉

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

    bro plz do in python

  • @ashishsonii
    @ashishsonii 3 месяца назад

    Dont stop DSA questions

  • @YNKeerthi-ry6jx
    @YNKeerthi-ry6jx 8 месяцев назад +1

    koko eating banana 875 leetcode question

    • @nikoo28
      @nikoo28  7 месяцев назад +1

      It is available now: ruclips.net/video/JGYXNpZaW2U/видео.htmlsi=2ftslOTD1LCE8-r2

  • @abhinavd2
    @abhinavd2 2 года назад

    100

  • @ssss22144
    @ssss22144 Месяц назад

    😢

  • @RajuBandaru-x1d
    @RajuBandaru-x1d 11 дней назад

    Problem 1:
    Description:
    Given a number
    𝑛
    n, write a function to find the largest number that has the same set of digits as
    𝑛
    n but is smaller than
    𝑛
    n. If no such number exists, return an appropriate message.
    Example:
    Input:
    𝑛
    =
    531476
    n=531476
    Output:
    531467
    531467