Home › Learn › World 7: Chain Railway
PREMIUMRunaway Express
Reversing a linked list in place
World 7 boss of Code the Hero, in Chain Railway: linked lists: follow the couplings.
What you practise
Reversing a linked list in place. 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.
Boss: Runaway Express. Beat it to restore Chain Railway.
What it costs
| Time | O(n) |
| Extra space | O(1) |
How the stars are earned
- Reversed on every test
- At most 3n + 1 relinks
- At most n + 1 relinks: one pass
Your code is also checked on hidden inputs, so it has to work for any case, not only the one on screen.
Worlds 1–3 (21 levels) are free. Chain Railway is part of Premium.
More in Chain Railway
- Walk the Train: Traversing a linked list, O(n)
- Couple a Car: Inserting into a linked list, O(1) once found
- Uncouple: Deleting from a linked list
- Middle Car: Tortoise and hare, one pass
- Loop Track: Floyd's cycle detection, O(1) space
- Merge Yards: Merging sorted linked lists, O(n + m)