~/DHRUVUpskilling
← board/DSA/Fast and Slow Pointer/dsa-fast-and-slow-pointer-02
Backlog·queued

Linked List Cycle

DifficultyMedium
PatternFast and Slow Pointer
TrackDSA
tl;dr

Check whether or not a linked list contains a cycle. If a cycle exists, return TRUE. Otherwise, return FALSE. The cycle means that at least one node can be reached again by traversing the next pointer.

full write-up

Constraints

Let n be the number of nodes in a linked list.

  • 0 ≤ n ≤ 500
  • −10⁵ ≤ Node.data ≤ 10⁵