Pointers that only look forward: walking the chain, fast and slow pointers and finding cycles.
Key ideas
- From a node you can only go forward with
next; to look back you must keep values somewhere. - Fast and slow pointers: one takes two steps, the other one. They find the middle and cycles in a single walk.
- Compare nodes with
is: two nodes with the same value can still be different nodes.
Pattern
node = head
while node:
# use node.val
node = node.nextFinish these first:Two Pointers & Sliding Window
Lessons
Each lesson explains one idea from zero and ends with a few tasks. Lessons open in order; the explanation can be read at any time.
Boss
05
Where the Loop Begins
Function
The boss opens when every lesson of the topic is finished. Solve it too and the topic is complete, and the topics after it open.