Quant Memo
Coding/●●●●●

Measure the length of a linked list's cycle

A traversal has confirmed that a linked list contains a cycle. The next diagnostic question from your monitoring system is: how big is the loop?

1 -> 2 -> 3 -> 4 -> 5
          ^         |
          +---------+     # 5 points back to 3: cycle length 3

Return the number of nodes in the cycle in O(n)O(n) time and O(1)O(1) space. Return 00 if there is no cycle.

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions