Daily Dose of LeetCode: Two Sum

Sdílet
Vložit
  • čas přidán 15. 06. 2024
  • Hello everyone, this is YOUR Daily Dose of LeetCode (Definitely didn't copy ‪@DailyDoseOfInternet‬ )
    In this video, we're tackling the popular Two Sum problem. We'll not only discuss the key takeaways but also delve into understanding the best possible runtime, and explore both brute force and optimized solutions.
    Mastering problems like Two Sum is a critical step in your journey as a software developer and in acing that coding interview.
    Remember to like, comment, and subscribe to keep up with our LeetCode problem-solving guides, and let me know in the comments if you have any other problems you'd like me to cover.
    (Had to reupload since there was a mistake in the brute force solution, whoops)
    // TIMESTAMPS //
    00:00 - Intro
    00:19 - What are the key takeaways?
    00:43 - What's the best runtime that we can do?
    01:00 - Brute Force Solution
    01:35 - Optimized Solution
    // SOCIALS //
    Twitter: / thecodingsloth1
    TikTok: / thecodingsloth
    #leetcode #twosum #python #codinginterview #algorithm #programming #coding #pythonprogramming #codingtutorials #computerscience

Komentáře • 25

  • @amrrahmy123
    @amrrahmy123 Před 8 měsíci +13

    the funny thing is, two loops is actually faster, because checking and adding to a hashmap is an expensive step. So even if it only took one loop, you are doing a lot more work and taking more space in memory in each iteration which demonstrates that O notation is a flawed way of evaluating solutions.

    • @zalanborbely9177
      @zalanborbely9177 Před 12 dny

      is that true for c++ as well?

    • @amrrahmy123
      @amrrahmy123 Před 11 dny

      @@zalanborbely9177 yes, you are at least doubling the memory usage, creating a runtime map and adding an additional check. you might think you only looped once, but in each iteration you are going through the hashmap that's already there, adding to it in the loop as well.
      saying 1 loop is better than 2 loops doesn't take into account that one of them is an fat or expensive loop while the other is a slim loop.

    • @zalanborbely9177
      @zalanborbely9177 Před 11 dny

      @@amrrahmy123 thats really interesting, but in interviews they still want you to do the hash map solution i assume

  • @vyy00bet
    @vyy00bet Před 10 měsíci +4

    I loved this format of video. Keep it up man

  • @official_mosfet
    @official_mosfet Před 9 měsíci +1

    Why you have just 539 subscribers? Underrated, for no reason.

  • @ashishkushwaha2910
    @ashishkushwaha2910 Před 10 měsíci

    like that you are at top of my search and its grate for you as a starter on you tube. I also liked your style of video can you tell me what and how you do that. like those subtitle and sketches.

    • @TheCodingSloth
      @TheCodingSloth  Před 10 měsíci

      Thanks! I'm using Adobe Premiere for all my editing, subtitles, and sketches

  • @billy8461
    @billy8461 Před 10 měsíci +3

    they assigned me this problem during my interview but I had to find all pairs and not include dups

    • @Trizzi2931
      @Trizzi2931 Před 9 měsíci

      Seems easy just keep a hast table that is pair to bool which keeps track of if the pair is part of answer or not. Did you solve it?

    • @billy8461
      @billy8461 Před 9 měsíci

      @@Trizzi2931 yeah and gott the job :)

  • @aliaryan786110
    @aliaryan786110 Před 8 měsíci +1

    Bro is there a good resource for DSA in python. Most resources are in c++/java. Stuck between learning DSA first in C++ then thinking to switch to python. But it's all time consuming.

  • @Lofisasddle
    @Lofisasddle Před 10 měsíci +2

    keep it up bro see if you can use c++

    • @TheCodingSloth
      @TheCodingSloth  Před 10 měsíci

      Thanks bro, I'll try to add multiple languages in other videos, currently thinking of Python, C++, and Java

  • @Snollygoster-
    @Snollygoster- Před 9 měsíci

    the space complexity can be eliminated if you just use 2 pointers.
    while (arr[a] + arr[b] != target)
    if arr[a] + arr[b} > target; b b--
    else a++;
    That being said though, space complex solutions are usually prettier. Basically every recursive function always has a o(n) space complexity and it sucks because they're so beautifully simple.

    • @tianchengteh1695
      @tianchengteh1695 Před 8 měsíci

      That assumes that the list is sorted, which it might not be.

    • @Snollygoster-
      @Snollygoster- Před 8 měsíci +1

      @@tianchengteh1695
      That's fair, any of the actual test cases would have rekt that strategy (now that I've actually looked)

    • @tianchengteh1695
      @tianchengteh1695 Před 8 měsíci

      @@Snollygoster- yeah lol

  • @brunofeitosafl
    @brunofeitosafl Před 9 měsíci +1

    had to watch it in 0.5X haha

  • @Arthur_Heerdt
    @Arthur_Heerdt Před 12 dny

    i'm cooked

  • @fab8187
    @fab8187 Před 9 měsíci

    Bruh Can do better we can have O(N) Time and no space comlexity use 2 pointers