Back to course home
0% completed
Vote For New Content
It's possible to track the duplicates while performing the cyclic sort. I think ...
Nash Luffman
Mar 4, 2023
It's possible to track the duplicates while performing the cyclic sort. I think this is preferable to iterating over the array twice. The algorithm looks the exact same as Find the Duplicate Number, except instead of returning when a duplicate is found, you add it to the output array.
9
0
Comments
Comments
D
davemednikov 2 years ago
I agree with this. My solution checked for the duplicates in the first iteration of the array. I was quite surprised to see that the provided solution included a second iteration of the array.
E
Enes a year ago
That's true. In fact, I solved this first with a hash map and it felt simpler to me too. There are multiple ways of solving this problem.
On this page