- Tutorials
- DSA Tutorial
- Hash Maps and Sets
Hash Maps and Sets
2 lessonsAbout 12 minutesBeginner
This part of the DSA Tutorial runs from Hash Maps and Sets in JavaScript through to When a Hash Map Is the Wrong Choice. There are 2 lessons here, and working through them takes about 12 minutes at a steady pace.
It follows on from Strings, so finish that first if you have not already — the examples below assume you are comfortable with it.
Each lesson below says what it covers before you open it. Read them in order the first time; afterwards this page works as a index you can jump back into when you need to check one thing.
- 1Hash Maps and Sets in JavaScriptMap and Set give you O(1) lookup, which turns most nested-loop problems into single passes. Learn how they work, when to use Map over a plain object, and what O(1) really costs.
- 2When a Hash Map Is the Wrong ChoiceHash maps are not always the answer. Learn when sorting, an array, or two pointers beats a Map — ordering, memory limits, small inputs and range queries.
