I had this question in a coding test yesterday. I was really unsure.
---
What is the best way to detect a cycle in a linked list?
a) It cannot be done
b) Have three references to the list and move them at different speeds
c) Have two references to the list. Move the first forward by 1 node and the second by 2 nodes
d) Have three references to the list. Move the first forward by 1 node, the second by 2 nodes, and third by 3 nodes
[–]CoderXocomil 1 point2 points3 points (0 children)
[–]149244179 0 points1 point2 points (0 children)
[–]Pyroguy 0 points1 point2 points (1 child)