Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

head =
pos =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

Use Floyd’s tortoise and hare cycle detection.

Approach

Move slow by 1 and fast by 2. If there’s a cycle they eventually meet; if fast reaches null there’s no cycle.

Why it works

In a cycle, the faster pointer gains on the slower pointer by 1 per step, guaranteeing a meeting.

Code
Loading...
Complexity
Time: O(n)
Space: O(1)
Solution
Updated: 2026-02-23

Idea

Use Floyd’s tortoise and hare cycle detection.

Approach

Move slow by 1 and fast by 2. If there’s a cycle they eventually meet; if fast reaches null there’s no cycle.

Why it works

In a cycle, the faster pointer gains on the slower pointer by 1 per step, guaranteeing a meeting.

Code
Loading...
Complexity
Time: O(n)
Space: O(1)