Re:I cheated on my Microsoft interview (2019)
by williamkuszmaul on Sunday June 05, 2022 @05:40AM
(#31629406)
Unless I'm misreading, the question as stated in the blog post never says there is only one duplicate (there might be many!), so in that sense I think his answer may be wrong. A more robust solution is just to have an array of n counters and just count how many times each item appears.
[ Parent
| on HN ]
Re:I cheated on my Microsoft interview (2019)
by philiiiiiipp on Sunday June 05, 2022 @05:50AM
(#31629460)
> when given an array of length n + 1 containing integers 1 through n, find the duplicate integer in an array.
I do believe it is only one.
The length is n+1 and contains all ints 1 through n, so there can only be a single duplicate.
Re:I cheated on my Microsoft interview (2019)
by williamkuszmaul on Sunday June 05, 2022 @11:49AM
(#31632049)
But does the question ever say "all"...?