You almost never build a hash map yourself — every language ships a fast one. This lesson is the toolkit: the same operations in all four languages, the one idiom you'll type more than any other (counting), and the traps that catch people in each language.
All of these are O(1) on average, except looping, which visits every entry. For a set, use Set (JavaScript), set() (Python), HashSet (Java) or unordered_set (C++) — the same operations without values.
Members only · free account
The rest of this lesson, with 4 more sections, a dry-run simulator and code in JavaScript, Python, Java and C++, opens with a free account.
Not ready yet? The Arrays course is free to read, no account needed.
In the rest of this lesson