Code fundamentals
The concepts that keep coming up in technical tests: a little theory and problems from easier to harder.
All concepts
Loading your progress…
In TypeScript, JavaScript, Python or PHP: pick the language above the editor.
Nested loops vs maps and sets
Swap a loop inside a loop for a Set or a Map: from O(n²) to O(n).
- Any duplicate?10 min · with a performance test
- Two that add up to the target15 min · with a performance test
- Items in common15 min · with a performance test
- Are they anagrams?10 min · with a performance test
- The first character that doesn't repeat10 min · with a performance test
- Group anagrams15 min
- Improve this: unique visitorsImprove this · 10 min · with a performance test
Sort to simplify
Sort first and the problem becomes a single pass: intervals, gaps, rankings.
Binary search
Halve the range at every step: O(log n) over sorted data or an answer you can check.
Two pointers
Two indices moving in from both ends or in step, with no extra memory.
Sliding window
A window that grows and shrinks over the list to answer questions about contiguous runs in O(n).
Stacks and ring buffers
Last in, first out: brackets, undo and a fixed-size ring buffer.