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.
- Lists and 2D grids: Build grids with separate rows, step through neighbours safely, and know which list operations are slow. ~20 min
- Sorting and tuples: Sort with
keyandreverse, use tuples for multi-rule orders, and rely on stable sorts. ~20 min - 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
- Deques and heaps: Use a deque for queues and sliding windows, and a heap for repeated smallest-item queries. ~20 min
- Built-in helpers, itertools, bisect, and functools: Use
zip,maxwith a key, prefix sums, sorted-list counting, memoisation, and exact integer math. ~25 min