Hacker News new | ask | show | jobs
by williamkuszmaul 1480 days ago
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.
2 comments

> 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.
But does the question ever say "all"...?