Ctrl K
Problem

Flip the Chain

Easy · Flip the Chain

Train cars are coupled into a singly linked list: each node knows only the next one. You are given the list's `head`. Recouple the cars so they run in the opposite order, and return the new head, which is the former last node. An empty list (`head` is `None`) stays empty. Try solving it two ways: with a loop and with recursion.…

Solve the problem →