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

  Рет қаралды 17,688

AlgosWithMichael

AlgosWithMichael

Күн бұрын

Пікірлер: 44
@swargyahi904
@swargyahi904 15 күн бұрын
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
@imranmohammed9814
@imranmohammed9814 9 күн бұрын
No extra space allowed.
@hiradr3857
@hiradr3857 3 жыл бұрын
There is no way someone can come up with this solution in 30 minutes if they haven't seen it before lol
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
Lol agreed
@felixtube71
@felixtube71 4 ай бұрын
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 4 ай бұрын
dont get me wrong, your's is cool, i was just curious.
@jorgegallego9672
@jorgegallego9672 26 күн бұрын
time complexity has to be O(n)
@StateofMichigan-26thState
@StateofMichigan-26thState 3 жыл бұрын
Dude, You Rock!
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
Thanks Ethan! I appreciate you watching and commenting
@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 жыл бұрын
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!
@mixupthings
@mixupthings 2 жыл бұрын
how do you get the Approach in first time??
@rchukkapalli1
@rchukkapalli1 4 жыл бұрын
on line 12, we can just add => result.add(nums[i])?
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
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
@MrAbhinandan19
@MrAbhinandan19 3 ай бұрын
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 2 ай бұрын
It can't because of the constraints
@oooo-rc2yf
@oooo-rc2yf 2 жыл бұрын
Brilliantly simple implementation of permutation cycles, thanks for the walk through, due to that I was finally able to get it to click.
@heisenberg1844
@heisenberg1844 4 жыл бұрын
All your explanations are wonderful. Thank You.
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
You are welcome!
@ManvendraSK
@ManvendraSK 4 жыл бұрын
Please keep doing this stuff. I also try this stuff but in JavaScript. Thanks.
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
I definitely will, thanks for watching!
@tanweerchiktay
@tanweerchiktay 3 күн бұрын
Hi
@jeffge8009
@jeffge8009 3 жыл бұрын
I wonder without knowing the solution in advance, how many people are able to come up with this solution during the 30min interview??
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
Likely not very many, myself included!
@kalyanamvenumadhav2245
@kalyanamvenumadhav2245 6 ай бұрын
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 ?
@elmeroranchero
@elmeroranchero 8 ай бұрын
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.
@code7434
@code7434 4 жыл бұрын
Please cover more popular problems , that have these kind of tricky ways to reduce space complexity. Really liked the way u solved this problem
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
I will try my best! Thank you for watching :)
@noureddineettalhi9825
@noureddineettalhi9825 2 жыл бұрын
I saw only a video of your "slipping-window" so far, and I can already tell you are a great person. concision is good.
@MBindu-kc2nj
@MBindu-kc2nj 2 жыл бұрын
I hope I will get offer because of you thank you in advance
@htphong24
@htphong24 2 жыл бұрын
Thanks a lot bro, you always have an excellent way of explaining solutions.
@MBindu-kc2nj
@MBindu-kc2nj 2 жыл бұрын
Very helpful.Thank you so much 🤗
@MBindu-kc2nj
@MBindu-kc2nj 2 жыл бұрын
Lots of love thank you
@code7434
@code7434 4 жыл бұрын
Amazing
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
Thank you!
@maldannak6568
@maldannak6568 4 жыл бұрын
Thanks lot😊. Nice job your doing
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
Thank you!
@bhavyachawla7176
@bhavyachawla7176 4 жыл бұрын
amazing explanation !!!
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
Glad it was helpful!
@ParkourGenerationNew
@ParkourGenerationNew 5 ай бұрын
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
Amazon Coding Interview Question - Number of Distinct Islands
17:43
AlgosWithMichael
Рет қаралды 24 М.
А ВЫ ЛЮБИТЕ ШКОЛУ?? #shorts
00:20
Паша Осадчий
Рет қаралды 9 МЛН
Players vs Corner Flags 🤯
00:28
LE FOOT EN VIDÉO
Рет қаралды 70 МЛН
LeetCode was HARD until I Learned these 15 Patterns
13:00
Ashish Pratap Singh
Рет қаралды 370 М.
Javascript Coding Interview Questions- You Must Know Them
17:06
Monsterlessons Academy
Рет қаралды 17 М.
Easy Google Coding Interview With Ben Awad
28:00
Clément Mihailescu
Рет қаралды 1 МЛН
Amazon Coding Interview Question - Integer to Roman (LeetCode)
9:06
AlgosWithMichael
Рет қаралды 20 М.
Kadane's Algorithm - Maximum Subarray (Dynamic Programming)
8:24
AlgosWithMichael
Рет қаралды 25 М.
5 Most Common Amazon Coding Interview Questions for 2022
21:52
Google Coding Interview With A Facebook Software Engineer
49:59
Clément Mihailescu
Рет қаралды 937 М.