Brilliantly simple implementation of permutation cycles, thanks for the walk through, due to that I was finally able to get it to click.
@noureddineettalhi98252 жыл бұрын
I saw only a video of your "slipping-window" so far, and I can already tell you are a great person. concision is good.
@hiradr38574 жыл бұрын
There is no way someone can come up with this solution in 30 minutes if they haven't seen it before lol
@AlgosWithMichael4 жыл бұрын
Lol agreed
@lylez00Ай бұрын
I've been interviewing lately, and I'm not encountering any of these "common questions" I'm seeing on KZbin. 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!
@code74344 жыл бұрын
Please cover more popular problems , that have these kind of tricky ways to reduce space complexity. Really liked the way u solved this problem
@AlgosWithMichael4 жыл бұрын
I will try my best! Thank you for watching :)
@heisenberg18444 жыл бұрын
All your explanations are wonderful. Thank You.
@AlgosWithMichael4 жыл бұрын
You are welcome!
@lylez00Ай бұрын
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.
@elmeroranchero10 ай бұрын
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.
@ManvendraSK4 жыл бұрын
Please keep doing this stuff. I also try this stuff but in JavaScript. Thanks.
@AlgosWithMichael4 жыл бұрын
I definitely will, thanks for watching!
@kasir-baratiАй бұрын
So basically we flip the numbers as a sign to see if we have already been there.
@mixupthings3 жыл бұрын
how do you get the Approach in first time??
@swargyahi9042 ай бұрын
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
@imranmohammed98142 ай бұрын
No extra space allowed.
@htphong242 жыл бұрын
Thanks a lot bro, you always have an excellent way of explaining solutions.
@jeffge80093 жыл бұрын
I wonder without knowing the solution in advance, how many people are able to come up with this solution during the 30min interview??
@AlgosWithMichael3 жыл бұрын
Likely not very many, myself included!
@kalyanamvenumadhav22458 ай бұрын
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 ?
@SusantaKumar-c4jАй бұрын
how to handle if any index value is more than the length of the array
@MrAbhinandan195 ай бұрын
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.
@williamTjS3 ай бұрын
It can't because of the constraints
@rchukkapalli14 жыл бұрын
on line 12, we can just add => result.add(nums[i])?
@AlgosWithMichael4 жыл бұрын
We can't do that because nums[i] could be a negative number since on line 13 we swap signs.
@akashjoshi32983 жыл бұрын
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
@ParkourGenerationNew6 ай бұрын
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
@MBindu-kc2nj2 жыл бұрын
Very helpful.Thank you so much 🤗
@sajalagarwal34864 жыл бұрын
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?
@AlgosWithMichael4 жыл бұрын
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!
@StateofMichigan-26thState3 жыл бұрын
Dude, You Rock!
@AlgosWithMichael3 жыл бұрын
Thanks Ethan! I appreciate you watching and commenting
@MBindu-kc2nj2 жыл бұрын
Lots of love thank you
@maldannak65684 жыл бұрын
Thanks lot😊. Nice job your doing
@AlgosWithMichael4 жыл бұрын
Thank you!
@bhavyachawla71764 жыл бұрын
amazing explanation !!!
@AlgosWithMichael4 жыл бұрын
Glad it was helpful!
@MBindu-kc2nj2 жыл бұрын
I hope I will get offer because of you thank you in advance
@code74344 жыл бұрын
Amazing
@AlgosWithMichael4 жыл бұрын
Thank you!
@tanweerchiktayАй бұрын
Hi
@felixtube716 ай бұрын
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?
@felixtube716 ай бұрын
dont get me wrong, your's is cool, i was just curious.