CODE THE HERO

Home › Learn › World 7: Chain Railway

PREMIUM

Loop Track

Floyd's cycle detection, O(1) space

Level 7.5 of Code the Hero, in Chain Railway: linked lists: follow the couplings.

What you practise

Floyd's cycle detection, O(1) space. You write real Python, Java or JavaScript, press Run, and the hero acts out every line, so you can see why the fast way is fast.

What it costs

TimeO(n)
Extra spaceO(1)

How the stars are earned

  1. Correct verdict on every test
  2. Solved (storing cars in a Set is fine)
  3. No cars stored, at most 3n + 2 steps

Your code is also checked on hidden inputs, so it has to work for any case, not only the one on screen.

▶ Start free with World 1See Premium

Worlds 1–3 (21 levels) are free. Chain Railway is part of Premium.

More in Chain Railway