← All topics

Lesson

Hash Map & Set

Average O(1) lookup to trade space for time.

Easy → MediumTime O(n)Space O(n)
Practice problems
Loading visualization…

Loading solution…

Complement pattern

Store what you have seen. For each x, check if target−x exists. This turns nested loops into one pass.

Counting

Anagrams, majority element, and isomorphic strings are frequency problems in disguise.

Pitfalls

  • !Mutable keys
  • !Assuming order
  • !Worst-case hash collisions in adversarial inputs

Practice from this topic

Showing 24 of the related problems in the 1000-question bank.

View all →

Got the lesson?

Mark Hash Map & Set as understood when the ideas stick.