Amazon Coding Interview Question - Find All Duplicates in Array [LeetCode]

Поділитися
Вставка
  • Опубліковано 28 січ 2025

КОМЕНТАРІ • 49

  • @noureddineettalhi9825
    @noureddineettalhi9825 3 роки тому

    I saw only a video of your "slipping-window" so far, and I can already tell you are a great person. concision is good.

  • @oooo-rc2yf
    @oooo-rc2yf 3 роки тому +2

    Brilliantly simple implementation of permutation cycles, thanks for the walk through, due to that I was finally able to get it to click.

  • @hiradr3857
    @hiradr3857 4 роки тому +11

    There is no way someone can come up with this solution in 30 minutes if they haven't seen it before lol

  • @heisenberg1844
    @heisenberg1844 4 роки тому +4

    All your explanations are wonderful. Thank You.

  • @mixupthings
    @mixupthings 3 роки тому +2

    how do you get the Approach in first time??

  • @SusantaKumar-c4j
    @SusantaKumar-c4j 3 місяці тому

    how to handle if any index value is more than the length of the array

  • @lylez00
    @lylez00 3 місяці тому

    I wondered if the nums[index] = -nums[index] should be under an else statement, but when I tried that, in one of my test cases, it printed out one of the duplicate values twice.

  • @ManvendraSK
    @ManvendraSK 5 років тому +3

    Please keep doing this stuff. I also try this stuff but in JavaScript. Thanks.

  • @code7434
    @code7434 4 роки тому +1

    Please cover more popular problems , that have these kind of tricky ways to reduce space complexity. Really liked the way u solved this problem

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

    on line 12, we can just add => result.add(nums[i])?

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

      We can't do that because nums[i] could be a negative number since on line 13 we swap signs.

    • @akashjoshi3298
      @akashjoshi3298 3 роки тому

      Abs(nums[i]) can be added nd i think we should use set for storing the result instead of list because if any value present 4 times then this solution will add that particular value 2 times, which we don't need i think

  • @elmeroranchero
    @elmeroranchero Рік тому

    I guess the problem description is misleading, declaring an additional array/collection is extra space, specially arrayList and the kind, since those structures always have a buffer for adding elements.

  • @kalyanamvenumadhav2245
    @kalyanamvenumadhav2245 10 місяців тому

    Why we need to take negative based indexing can u ckarify this as you said that it's an zero based indexing and nunbers atarts from 1 to n then why we are taking negative indexing can't we get without that ?

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

    Thanks a lot bro, you always have an excellent way of explaining solutions.

  • @swargyahi904
    @swargyahi904 4 місяці тому

    Simply use hashmap store key as num and value as count and incr val if already present in map and eventually return key which is greater than 2 val

  • @lylez00
    @lylez00 3 місяці тому

    I've been interviewing lately, and I'm not encountering any of these "common questions" I'm seeing on UA-cam. They're all different, and they're all hard. My question today - just the question and the examples of solutions was 63 lines, and I had about 20 minutes to solve it. I am so sick of the IT industry!

  • @sajalagarwal3486
    @sajalagarwal3486 4 роки тому

    What if the elements doesn't lie in the range of the 1 to size of array?
    Then in that case what should be the most efficient approach?

    • @AlgosWithMichael
      @AlgosWithMichael  4 роки тому +3

      In that case I would use a HashSet. You can add all of the numbers inside of the set and any numbers that fail to be added you know are dups!

  • @JackLin-ct3wx
    @JackLin-ct3wx Місяць тому

    It becomes simple if you sort the input array. I don't know why it's a medium question.

  • @MBindu-kc2nj
    @MBindu-kc2nj 2 роки тому

    Very helpful.Thank you so much 🤗

  • @MrAbhinandan19
    @MrAbhinandan19 7 місяців тому

    This solution will give ArrayIndexOutOfBounds exception, if any value in the array is greater than or equal to total array length plus 2.
    For example, if this array had a value, say 15, then as per solution, 15 - 1, means 14th index and there is no 14th index in the array.

    • @williamTjS
      @williamTjS 6 місяців тому

      It can't because of the constraints

  • @MBindu-kc2nj
    @MBindu-kc2nj 2 роки тому

    Lots of love thank you

  • @maldannak6568
    @maldannak6568 4 роки тому

    Thanks lot😊. Nice job your doing

  • @StateofMichigan-26thState
    @StateofMichigan-26thState 3 роки тому

    Dude, You Rock!

    • @AlgosWithMichael
      @AlgosWithMichael  3 роки тому

      Thanks Ethan! I appreciate you watching and commenting

  • @bhavyachawla7176
    @bhavyachawla7176 4 роки тому

    amazing explanation !!!

  • @kasir-barati
    @kasir-barati 3 місяці тому

    So basically we flip the numbers as a sign to see if we have already been there.

  • @jeffge8009
    @jeffge8009 3 роки тому +2

    I wonder without knowing the solution in advance, how many people are able to come up with this solution during the 30min interview??

  • @MBindu-kc2nj
    @MBindu-kc2nj 2 роки тому

    I hope I will get offer because of you thank you in advance

  • @ParkourGenerationNew
    @ParkourGenerationNew 9 місяців тому

    What a sleek solution, nice! Although I was thinking technically you are using extra space for the minus signs. If the constraints are that the array elements are positive, then you don't need an array of integers, you can do it with an array of unsigned integers, which would save you half your space. Then you can can use the other half for a bool array (or even a bit array which would be like 8-16 times more space effecient) and make it a more clear/readable solution using the same space. But yeah, that's probably more complicated to think of during an interview

  • @code7434
    @code7434 4 роки тому +1

    Amazing

  • @tanweerchiktay
    @tanweerchiktay 4 місяці тому

    Hi

  • @felixtube71
    @felixtube71 8 місяців тому +1

    couldnt u sort with runtime of (n log n) then run thru array comparing i - 1 with i and then add dupe to result array?

    • @felixtube71
      @felixtube71 8 місяців тому

      dont get me wrong, your's is cool, i was just curious.

    • @jorgegallego9672
      @jorgegallego9672 4 місяці тому

      time complexity has to be O(n)