LeetCode #1: Two Sum | Coding Interview Solution

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

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

  • @mhdez3730
    @mhdez3730 Год назад +15

    Thank you for sharing your knowledge and expertise with the world!

  • @lazarus8011
    @lazarus8011 4 месяца назад +3

    Extremely clear and well presented video. Here's a comment for the RUclips algorithm.

  • @AndersonGomes-nf9vh
    @AndersonGomes-nf9vh 2 года назад +7

    You save me man, thank you. Now a can learn python and english with that subtitles.

  • @erinnyerin
    @erinnyerin 2 года назад +6

    Omg I needed this. YOU'RE AWESOME

  • @deyanlafchiev808
    @deyanlafchiev808 2 года назад +6

    Keep up bro! Your vids are extremly useful !

  • @returnZeroo
    @returnZeroo Год назад +4

    Learned a lot from the explanation.

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

    Great tutorial!

  • @gabrielvelazquezrios7324
    @gabrielvelazquezrios7324 4 дня назад

    Thank you, excellent explanation!

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

    You did an incredible job. Great explanation and pace!

  • @БабекАскеров-п7й
    @БабекАскеров-п7й 10 месяцев назад

    Ты великолепен! Куда отправить деньги чтобы поддержать твое творчество?🤗

  • @fardinabdullaacanto4715
    @fardinabdullaacanto4715 14 дней назад

    you made it a lot easier. TYTYTY

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

    Great video!

  • @polettiayala
    @polettiayala 9 месяцев назад

    incredible hard to be the first question!!!! I will try to study this a lot more, i will do a brute force in my mind in order to get what you did here!

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

    Keep going 🔥🎉

  • @despacitodaniel801
    @despacitodaniel801 Год назад +2

    oh my god my head hurts. Thank youy

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

    Waiting for upcoming videos

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

    Great explanation. I'm trying to imagine what that syntax would look like in Java.

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

    Best explanation out there!

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

    Your the best! Great video.

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

    Thanks bro for sharing your knowledge and for explaining clearly

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

    Great explanation and visualization, thank you

  • @ego_mejia
    @ego_mejia 9 месяцев назад

    Thank you for sharing your knowledge. You helped me a lot!

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

    very simple explanation thank you

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

    Thank you

  • @le-daniel
    @le-daniel Год назад +1

    Brute. This guy knows his Brute Forces

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

    ajig aing can ngarti, masih smp, rek ka smk jurusan rpl, bakal diajar anu kieu moal nya, siap siap heula we ah

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

    I see, so this is what I overlooked...

  • @Rekanized
    @Rekanized 9 месяцев назад

    But you are going to be copying memory here right? every single time you need to add a new value to the array, the array will be recreated in memory? Incase of the array being a lot larger than 3-6 int's the array will be changed multiple times which causes other issues right? is this really the greatest solution?

    • @AlgoEngine
      @AlgoEngine  9 месяцев назад

      We are not modifying the input array in any way. At each iteration, if the two numbers haven't been found, we only add a key-value pair to the "seen" dictionary, and dictionary insertions run in (amortized) O(1) time.

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

    Hello, I have one question regards to linear time solution which is mentioned here, I understand when we are traversing through the list only once.. While we are checking if the element i.e Target- list elem in dictionary we are doing o(1) n times which again corresponds to O(N) so O(n) * O(n).. sorry i m wrong, request you to please correct me.

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

      The misunderstanding here is that hash table (dictionary) lookup is not "O(1) n times" - it is just O(1). When checking if an element exists in a hash table, we do not iterate through all the keys. Instead, the element is converted into an "index" via a hash function, which allows you to jump straight to where the element should be in the hash table, similar to how array lookup is O(1) if you have the index.

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

      @@AlgoEngine Thank you ... Nice one !

  • @st-lucia
    @st-lucia Год назад

    I read somewhere that Sets can access index like Arrays/Lists.
    How do you overcome this? Tysm!

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

      You may be mistaken - sets and hash tables are inherently unordered so there is no concept of an index. However, with a hash table, you can access elements with a key instead, as we do in this problem.

    • @st-lucia
      @st-lucia Год назад

      @@AlgoEngine Yeah, I'm pretty new to this Python.
      I see at line 6 (3:54), you can use seen[diff], like array indices.
      Do you need to tell Python if 'seen' is a HashTable or Set beforehand?

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

      ​@@st-lucia Ah, so Python knows that "seen" is a Dictionary (hash table) because we initialized it using curly braces like this: seen = {}. You could also do it like this: seen = dict().
      Now, to access elements inside a hash table, we use a key (instead of an index for an array). seen[diff] returns the value corresponding to the key of diff, but remember, hash table keys can be anything and have no order (unlike array indexes, which must be ordered integers).

    • @st-lucia
      @st-lucia Год назад +1

      @@AlgoEngineok
      Kind of get it now.
      I will try to run the code, thank you again for the help!

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

    which video editing software are you using to make this video?

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

      I mainly use HTML, CSS, and JavaScript to make these, and occasionally PowerPoint.

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

      @@AlgoEngine 😍😍😍 thanks so much

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

    What software you use for animations ?

    • @AlgoEngine
      @AlgoEngine  Год назад +2

      I mostly use HTML, CSS, and JavaScript to create these. Occasionally, PowerPoint for the shorter ones.

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

    My brain just died i have no knowledge of math since i didn't listen when i was in highschool, any tips to begin?

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

      Start with learning/reviewing all the basic algorithms and data structures and understanding their time and space complexities. After you have the basics down, the best way to learn is to practice! I'd recommend setting aside 20-30 min for each problem (depends on how much time you have), and if you don't get it by then, just look at the solution but make sure you understand it. Then after a few days, revisit the problem and try to solve it without looking at the solution.

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

    Try to always keep the original LC # in your title.

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

    Your optimized solution not O(n) in worst case it still O(n^2), becouse "diff in seed" = diff in seen.keys() is O(n) lookup.

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

      I address this point at 4:59. Those two methods are not the same because "diff in seen" is O(1) but "diff in seen.keys()" is O(n). Hash table collisions could degrade the performance, but if the hash table is well implemented, this should rarely happen so the amortized complexity is still O(1). See the discussion here for more information: stackoverflow.com/a/17539425

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

    aren't you fucked if the array has dupes?

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

      Only if the duplicates create multiple solutions, but this problem assumes that there is exactly one solution. If multiple solutions were allowed, it would depend on whether you need to return all solutions or just one of the solutions. If you only need to return one, nothing changes, but if you must return all, then yes, you’d have to take a different approach.

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

    Such a clear and well-explained video, thank you! 🩵