Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

What is the area of the largest rectangle that fits in the histogram with bar heights [2, 1, 5, 6, 2, 3]?

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

Correct answer: D. 10

The monotonic stack pops bars taller than the current one, and each popped bar's rectangle spans between its smaller neighbours. Heights 5 and 6 over two bars give 10; 12 misreads the width as 2 at height 6, 6 is the tallest bar alone and 19 sums every bar.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic