easyLinked ListPure DSA~13 min
Session Ring Cycle Check
A session-handoff chain is a linked list of nodes; a misconfigured failover can splice a node back to an earlier one, creating an infinite loop. Detect whether the chain cycles.
Problem
Given the head of a singly linked list, return true if the list contains a cycle — some node's next pointer points back to a previously visited node — and false otherwise. Solve in O(1) extra space.
Input
The head node of a singly linked list (0 ≤ nodes ≤ 10^4).
Output
A boolean — true if a cycle exists.
Constraints
- Use O(1) auxiliary space
- The list may be empty
- Node values are irrelevant to the answer
Examples
Example 1
Input
3 → 2 → 0 → -4, where -4.next points back to node 2
Output
true
Traversal re-enters node 2, so a cycle exists.
Example 2
Input
1 → 2 → null
Output
false
Traversal reaches null without repeating a node.