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.
This commit is contained in:
parent
3ff6ae3697
commit
062af32e4e
2 changed files with 116 additions and 2 deletions
|
|
@ -26,7 +26,7 @@
|
|||
** DONE 2nd Largest Item in a Binary Search Tree
|
||||
** DONE Graph Coloring
|
||||
** DONE MeshMessage
|
||||
** TODO Find Repeat, Space Edition BEAST MODE
|
||||
** DONE Find Repeat, Space Edition BEAST MODE
|
||||
* Dynamic programming and recursion
|
||||
** TODO Recursive String Permutations
|
||||
** TODO Compute nth Fibonacci Number
|
||||
|
|
@ -45,7 +45,7 @@
|
|||
** TODO Does This Linked List Have A Cycle?
|
||||
** TODO Reverse A Linked List
|
||||
** TODO Kth to Last Node in a Singly-Linked List
|
||||
** TODO Find Repeat, Space Edition BEAST MODE
|
||||
** DONE Find Repeat, Space Edition BEAST MODE
|
||||
* System design
|
||||
** TODO URL Shortener
|
||||
** TODO MillionGazillion
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue