Hardware interview practice
Detect a linked-list cycle
Return 1 when a singly linked list contains a cycle and 0 when it terminates at null.
Reviewed example
Work through one case
Input
1 -> 2 -> 3, with node 3.next pointing back to node 2Expected output
1 (cycle present)The slow and fast pointers eventually meet inside the 2 -> 3 loop without modifying the list.
What to cover
Requirements
- Use constant extra space.
- Handle empty and one-node lists safely.
- Do not modify list links.
