Coding & data structures · Hashing, counting, and prefix sums

Sets, canonical keys, and the seen-set invariant

Choosing the key is the design decision in most hashing problems — a sorted string versus a count signature for grouping, why an array can't be a key in JavaScript but a tuple can in Python, how a set turns an O(n log n) sequence problem into an amortised O(n) one, and the three cases where a set is the wrong structure entirely.

20 min read Full lesson in the app Patterns: canonical key, grouping, seen-set, amortised counting

What you'll be able to do

Before this: hash-maps, counting-and-frequency

The rest of this lesson is in the app

Choosing the key is the design decision in most hashing problems — a sorted string versus a count signature for grouping, why an array can't be a key in JavaScript but a tuple can in Python, how a set turns an O(n log n) sequence problem into an amortised O(n) one, and the three cases where a set is the wrong structure entirely. This walkthrough runs about 20 minutes, with runnable code you can edit and re-run as you read.

Continue in ChannelPulse

The first module of every track is free to read on the web — see what's open in Coding & data structures.