Skip to content
CodeItRaw
Path

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.next

Finish 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.

  1. 01

    Nodes and next

    0/2 tasks

  2. 02

    The fast and the slow pointer

    0/2 tasks

  3. 03

    The gap between them, and their meeting

    0/2 tasks

  4. 04

    Turning the links round

    0/2 tasks

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.