Skip to content

Part 5: Competitive programming data structures

This part covers the built-in data structures and helper tools that contest solutions use most: lists and 2D grids, sorting with keys, sets and dictionaries with an anti-hash defence, deques and heaps, and the built-in functions with itertools, bisect, and functools. Work through the lessons in order, because each one uses the ideas of the lessons before it.

  1. Lists and 2D grids: Build grids with separate rows, step through neighbours safely, and know which list operations are slow. ~20 min
  2. Sorting and tuples: Sort with key and reverse, use tuples for multi-rule orders, and rely on stable sorts. ~20 min
  3. Sets, dictionaries, and anti-hash tests: Count and look up with hash tables, and spread out crafted integer keys with a mixing step. ~25 min
  4. Deques and heaps: Use a deque for queues and sliding windows, and a heap for repeated smallest-item queries. ~20 min
  5. Built-in helpers, itertools, bisect, and functools: Use zip, max with a key, prefix sums, sorted-list counting, memoisation, and exact integer math. ~25 min