Commit graph

1 commit

Author SHA1 Message Date
William Carroll
062af32e4e Solve InterviewCake's find duplicate beast mode
Write a function to find a duplicate item in a list of numbers. The values are
in the range [1, n]; the length of the list is n + 1. The solution should run in
linear time and consume constant space.

The solution is to construct a graph from the list. Each graph will have a cycle
where the last element in the cycle is a duplicate value.

See the solution for specific techniques on how to compute the length the cycle
without infinitely looping.
2020-03-26 11:55:06 +00:00