Given a singly linked list, explain how you would determine whether it contains a cycle. A cycle exists when a node's next pointer points back to a previously visited node.
For example, consider: 1 -> 2 -> 3 -> 4 -> 2 (node 4 points back to node 2). This list has a cycle.
Can you solve this in O(1) space? How would you also find the node where the cycle begins?
Explain your approach and analyze the time and space complexity.
How to approach it
- Hint 1
Consider using two pointers that move at different speeds.
- Hint 2
If a slow pointer moves one step at a time and a fast pointer moves two steps, what happens if there is a cycle?
- Hint 3
To find the cycle start: once the two pointers meet, reset one to the head and move both one step at a time. They will meet at the cycle start.
Ready to answer it out loud?
Record your answer in 1:30 and Preptile scores it 1–10 with specifics — what landed, what you skipped, and what to say next time.
Practising needs an invite code. Join the waitlist and we’ll send you one.