My turn!
My friend posed a problem at me yesterday (and gave me the solution, thankfully
). I figured I'd post it here and see if others come to the same solution.
You have a list of numbers from 1 to n. Exactly one of the numbers is repeated once, and the rest of the numbers are present. The list is not in order. What is the best way to determine which number is repeated?
(Note: sorting the list then doing a search is O(nlog(n)), which is not the best solution)
(Hint: you only have to go over the list once, so the best solution is O(n)).