Linked lists

Nodes joined by links, and how to reverse one.

Each node holds a value and a link to the next node. Adding at the front is O(1), but reaching the kth item is O(n).

Expected output
3 2 1 

To find the middle or detect a loop, walk two pointers at different speeds. The fast one moves two steps for every one step of the slow one.

โ† Stacks and queuesHash maps โ†’