core practice · coding problem

Merge Intervals

LeetCode #56 — Merge Intervals. Solve on LeetCode, then implement here if you want it in your drill queue. https://leetcode.com/problems/merge-intervals/

The mechanism

A hash map trades memory for time: it turns an O(n) scan for "have I seen this?" into an O(1) lookup. Most array problems that feel quadratic collapse to linear once you ask what you would store in a map keyed by value, complement, or frequency.

Study Arrays & Hashing

Expected evidence

Pass all LeetCode test cases for this problem.

Try this drill in the practice workspace →

Hints when you need them
  • Pattern hint: array hashing.
  • Start with brute force, then optimize time/space.
  • Write down invariants before coding.

Watch for these mistakes

  • Reaching for nested loops before asking "what would a hash map key on?"
  • Mutating a collection while iterating it
  • Forgetting hash maps have no order — sort separately if order matters

Check the sources

Practice the same mechanism

Browse all practice briefs