Skip to content

Arrays & Hashing

An array is a numbered row of boxes. A hash map is a labelled drawer cabinet: give it a key and it hands back the value instantly. Almost every interview problem starts here, because the trick "remember what I have already seen" turns a slow double loop into one fast pass.

After this topic: You can spot when a nested loop can be replaced by one pass plus a map or set, and you can count, group and look things up in O(1).

0 of 9 solved0%

Step 1 · Read the lesson

Arrays & Hash Map

Trade memory for speed: look things up in O(1) instead of scanning again.

Step 2 · Solve the problems in order

Try each one for about 20 minutes first. Problems with a Run code tab are checked right here. If you are stuck, open Nudge, think again, then Idea. Go skeleton only gives the function shape, and Reference solution is for comparing after you have tried. Tick the box when you could solve it again without help.

  1. 1.Contains DuplicateEasy
  2. 2.Valid AnagramEasy
  3. 3.Two SumEasy
  4. 4.Group AnagramsMedium
  5. 5.Top K Frequent ElementsMedium
  6. 6.Encode and Decode StringsMedium
  7. 7.Product of Array Except SelfMedium
  8. 8.Valid SudokuMedium
  9. 9.Longest Consecutive SequenceMedium

Step 3 · What this unlocks