Fast & Slow Pointers/Easy

Linked List CyclePRO PASS

Time: O(N)Space: O(1)

Initialize Pointers prev=null, curr=head

Reversing a singly linked list in-place by flipping every next pointer. Set prev = null, curr = node 0 (3).

Linked List Pointers
curr
3
2
0
-4
null
Live Variables & Invariants
prev:null
curr:Node(3)
next:null
Step 1 / 138%
Solution Code
1
function hasCycle(head: ListNode | null): boolean {
2
  let slow = head, fast = head;
3
  while (fast && fast.next) {
4
    slow = slow.next!; fast = fast.next.next;
5
    if (slow === fast) return true;
6
  }
7
  return false;
8
}

Custom Test Case Runner

Input your custom values and visualize step-by-step trace

Quick Presets:

AI DSA Coach

Contextual Tutor for Linked List Cycle

Hello! I am your AI DSA Tutor for **Linked List Cycle** (Fast & Slow Pointers). Ask me anything about this algorithm, time complexity, or request a step hint!