🔁 Linked List Cycle II – Find the Start of the Cycle

Master LeetCode Problem Solving with Visual Understanding

Linked List Cycle II is one of the most frequently asked pointer-based interview problems.
At GoNimbus, you don’t just solve it — you see it, understand it, and explain it confidently in interviews.


🎯 Problem Overview

A linked list contains a cycle if a node can be revisited by continuously following the next pointer.

Your goal is to:

  • Detect whether a cycle exists
  • Identify the exact node where the cycle begins
  • Do it using constant extra space (O(1))

🧠 Why This Problem Is Important

This problem tests:

  • Deep understanding of pointer movement
  • Algorithmic reasoning (not memorization)
  • Space optimization techniques
  • Ability to explain logic clearly in interviews

It’s a must-know problem for product-based company interviews.

Linked List Cycle II – Find Cycle Start (Visualizer)

Nodes (comma separated): Cycle pos:
Slow Pointer Fast Pointer Meeting Point Cycle Start


🧩 Visual Learning with GoNimbus

Interactive Linked List Cycle II Visualizer

With our visualizer, you can:

  • Create linked lists with cycles using pos
  • Watch slow and fast pointers move step-by-step
  • See where pointers meet inside the cycle
  • Visually identify the cycle start node
  • Understand why the algorithm works — not just that it works

🔄 Two-Phase Algorithm Explained

Phase 1: Cycle Detection

  • Slow pointer moves 1 step
  • Fast pointer moves 2 steps
  • If they meet → cycle exists

Phase 2: Find Cycle Start

  • Reset slow pointer to head
  • Move both pointers one step at a time
  • The node where they meet again is the cycle start

This logic is visualized clearly in the GoNimbus visualizer.


📘 Example Scenario

Input:
head = [3, 2, 0, -4], pos = 1

Output:
Cycle starts at node with value 2

Explanation:
The tail connects back to the node at index 1, forming a loop.
Using Floyd’s algorithm, we detect the cycle and locate its entry point.


🔗 Linked List Cycle – Practice Problems with Diagrams

🧩 Problem 1: Detect Cycle (Basic)

Problem Statement

Given the head of a singly linked list, determine whether the list contains a cycle.
Return true if a cycle exists; otherwise, return false.


Example

Input:
head = [1, 2, 3, 4], pos = 1

Diagram:

1 → 2 → 3 → 4
     ↑         ↓
     └─────────┘

Output:
true

Explanation:
The last node connects back to the node at index 1, forming a cycle.


🧩 Problem 2: Find Cycle Start (Cycle II)

Problem Statement

If a cycle exists in the linked list, return the node where the cycle begins.
If no cycle exists, return null.


Example

Input:
head = [3, 2, 0, -4], pos = 1

Diagram:

3 → 2 → 0 → -4
     ↑           ↓
     └───────────┘

Output:
Node with value 2

Explanation:
The cycle begins at the node with value 2.
This node is returned as the cycle entry point.


🧩 Problem 3: Cycle at Head

Problem Statement

Check whether a linked list has a cycle where the tail connects back to the head node.


Example

Input:
head = [5, 6, 7], pos = 0

Diagram:

5 → 6 → 7
↑           ↓
└───────────┘

Output:
true

Explanation:
The last node connects directly to the head, creating a full circular list.


🧩 Problem 4: Single Node Cycle

Problem Statement

Determine whether a linked list with only one node forms a cycle.


Example

Input:
head = [1], pos = 0

Diagram:

1 ↺

Output:
true

Explanation:
The node points to itself, which is a valid cycle.


🧩 Problem 5: No Cycle Present

Problem Statement

Return whether the linked list contains a cycle when the list ends normally.


Example

Input:
head = [10, 20, 30], pos = -1

Diagram:

10 → 20 → 30 → null

Output:
false

Explanation:
The list terminates with null, so no cycle exists.


🧠 Key Notes for Learners

  • pos is used only to construct the input
  • pos is not passed to the function
  • Cycle detection depends on node references, not values
  • Floyd’s Algorithm solves all these cases in:
    • O(n) time
    • O(1) space

⏱ Complexity Analysis

  • Time Complexity: O(n)
  • Space Complexity: O(1)
  • No extra memory, no hash tables — interview-optimized solution

👩‍💻 Who Should Learn This?

  • DSA beginners learning linked lists
  • Students preparing for coding interviews
  • Professionals revising core patterns
  • Anyone struggling with pointer logic

🔁 Linked List Cycle II – 50 Interview Questions & Answers

🔹 Problem Understanding

1. What is Linked List Cycle II?

It is the problem of identifying the node where a cycle begins in a linked list, if a cycle exists.

2. How is it different from Linked List Cycle I?

Cycle I only detects if a cycle exists.
Cycle II finds the starting node of the cycle.

3. What should be returned if no cycle exists?

Return null.

4. Is the linked list allowed to be modified?

No, the list must remain unchanged.

5. What does pos represent?

It represents the index of the node where the tail connects, used only for input construction.


🔹 Algorithm & Logic

6. Which algorithm is commonly used?

Floyd’s Tortoise and Hare algorithm.

7. Why are two pointers used?

To detect a cycle and later locate its entry point using relative motion.

8. How fast does each pointer move in Phase 1?

Slow → 1 step
Fast → 2 steps

9. What indicates a cycle exists?

When slow and fast pointers meet.

10. Where do they meet?

Somewhere inside the cycle, not necessarily at the start.


🔹 Finding the Cycle Start

11. What happens after detecting the cycle?

Reset slow pointer to head.

12. How do pointers move in Phase 2?

Both move one step at a time.

13. When do we stop Phase 2?

When slow and fast meet again.

14. What does this meeting point represent?

The start of the cycle.

15. Why does resetting slow to head work?

Because distances from head and meeting point align mathematically.


🔹 Mathematical Intuition

16. What is the key distance relationship?

Distance from head to cycle start equals distance from meeting point to cycle start.

17. Why does fast pointer catch slow pointer?

Fast pointer gains one node per step inside the cycle.

18. Does cycle length matter?

No, the algorithm works for any cycle length.

19. Can the meeting point be the cycle start?

Yes, in some cases.

20. What if cycle starts at head?

Algorithm still correctly returns the head node.


🔹 Edge Cases

21. What if the list is empty?

Return null.

22. What if the list has one node without a cycle?

Return null.

23. What if the list has one node pointing to itself?

Return that node as cycle start.

24. What if the cycle is at the last node?

The last node is part of the cycle; entry is detected normally.

25. Can there be multiple cycles?

No, a linked list can have only one cycle.


🔹 Complexity

26. Time complexity?

O(n)

27. Space complexity?

O(1)

28. Why not use a HashSet?

HashSet uses O(n) extra space.

29. Which solution is preferred in interviews?

Two-pointer solution.

30. Can recursion be used?

No, recursion adds extra space.


🔹 Reference vs Value

31. What is compared: node value or node reference?

Node reference.

32. Why not compare node values?

Different nodes can have the same value.

33. Can duplicate values break the algorithm?

No.

34. Is pointer comparison language-specific?

No, it works in all languages.

35. What happens if values are negative?

Does not affect detection.


🔹 Follow-Up & Variations

36. How do you find the length of the cycle?

Count steps after meeting until pointer returns to meeting node.

37. How do you remove the cycle?

Find cycle start, then set previous node’s next to null.

38. How to detect cycle in doubly linked list?

Same approach works.

39. How to find cycle without modifying list?

Use Floyd’s algorithm.

40. How to return cycle index instead of node?

Traverse from head counting until cycle start node.


🔹 Common Mistakes

41. Forgetting to check fast.next for null

Causes runtime error.

42. Returning meeting point instead of cycle start

Incorrect for Cycle II.

43. Resetting fast instead of slow

Breaks logic.

44. Comparing values instead of references

Leads to wrong results.

45. Infinite loop in Phase 2

Occurs if pointers are not moved equally.


🔹 Interview Depth Questions

46. Why does this algorithm guarantee a solution?

Because relative motion ensures convergence.

47. Can fast pointer move 3 steps?

Yes, but unnecessary.

48. Why must slow start from head again?

To synchronize distances to cycle start.

49. What makes this problem tricky?

Understanding pointer math, not coding.

50. How would you explain this to an interviewer?

By visualizing pointer paths and distance equality.


✅ Final Tip for GoNimbus Learners

“Once you understand why the pointers meet again at the cycle start,
you’ll never forget this problem.”

Scroll to Top