Data Structures & AlgorithmsVery hardProduct Company SDE · ICPC regional

Problem: Find the area of the largest rectangle in a histogram with bar heights [2, 1, 5, 6, 2, 3] (each bar has width 1).

  1. A. 6
  2. B. 10
  3. C. 12
  4. D. 8

Correct answer: B. 10

A monotonic stack finds the best rectangle over bars 5 and 6: height 5 × width 2 = 10. The tallest single bar gives 6, assuming both of those bars reach 6 gives 12, and spreading height 2 over bars 5, 6, 2, 3 gives 8.

More Coding Interview Problems questions

Exams that ask this topic