Software interview question - Two Sum

Поділитися
Вставка
  • Опубліковано 22 жов 2024

КОМЕНТАРІ • 17

  • @DR-ex7yu
    @DR-ex7yu 2 роки тому

    With this detailed explanation I finally understood the solution! Thanks!!

  • @woozy_deer
    @woozy_deer 5 років тому +4

    yesss this is what I've been looking for!

  • @fredflintstone8048
    @fredflintstone8048 5 років тому +2

    Great! Keep them coming! Thank you.

  • @nournote
    @nournote 5 років тому +1

    Really interesting. Please keep it up. And the sooner, the better :)

  • @MrJonnis13
    @MrJonnis13 5 років тому +4

    Nice series. I like it a lot.
    A small correction though in your attempt to explain the basic idea.
    In the dictionary, the third row should be *Key:* 12 *Value:* 2 and not *Key:* 3 *Value:* 2

    • @JesseDietrichson
      @JesseDietrichson  5 років тому +4

      Yiannis Ioannidis damn you’re correct. Thanks I’ll get it fixed

    • @acca1461
      @acca1461 5 років тому +1

      Thanks for that also saw it

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

      I noticed professors also do small mistakes like that on purpose to make sure students are listening and paying attention

  • @acca1461
    @acca1461 5 років тому

    Can you please do more of these problems
    There are examples out there but no-one explains like you do, like how a program can be made more efficient by analyzing time complexities
    I greatly appreciate you uploading these especially now I'll be data structures and algorithms next semester by the way I'm doing Mechatronics in South Africa

  • @Aj-zr8dz
    @Aj-zr8dz 4 роки тому

    that sneaky 18 bugged me up

  • @bucifalro
    @bucifalro 5 років тому

    what would happen if there were two eights in this example array?

    • @JesseDietrichson
      @JesseDietrichson  5 років тому

      bucifalro it would return when it hit the first one.

  • @karsten600
    @karsten600 5 років тому

    It's really confusing when you try to explain what's returned in the integer array because you're using the plural form of the word 'index' (indexes/indecis) when it should be singular. You're literally saying: "It's just an int array with the first value being the first index, and the second value being the second index.", which doesn't make sense. I know what you meant to say, but I thought I'd point it out to help you improve.

    • @JesseDietrichson
      @JesseDietrichson  5 років тому

      karsten600 I completely see how this can be confusing. Let me try to clear confusion. Remember we’re trying to find 2 numbers that add up to the target value. We don’t want to return the actual two numbers in an array, instead we want to return their positions in the array. So since the answer in our example was 7 + 8 = 15. We want to return the index of value 7, which is 1, and the index of value 8, which is 3. Since there are two numbers we decide to return them using a brand new array. The first value in this new array is the first index (1) and the second value in this new array is the second index (3).

    • @karsten600
      @karsten600 5 років тому

      @@JesseDietrichson Yeah that's much better 😁👍

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

    [1,1,1,1,1,4,1,1,1,1,1,7,1,1,1,1,1] for this input it will fail. We need to add to dictionary only if the value is not present

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

      Yep I've seen similar solutions posted on multiple forums and this fails the edge case of duplicate values in the array. since C# dictionaries do not let you add duplicate keys.
      I coded the same thing and my leetcode kept failing because of it. My suggestion is to reverse it and use the indices as the keys and the values as the...values.