Data Structures & AlgorithmsHardGATE CS · TCS NQT

What is the area of the largest rectangle that fits in a histogram whose bar heights are 2, 1, 5, 6, 2, 3 (each bar has width 1)?

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

Correct answer: A. 10

The best rectangle spans bars 5 and 6 at height 5: area 10. A stack finds, for each bar, the widest span where it is the minimum. Height 2 over four bars gives 8, the tallest bar alone 6, and 19 is the total area of all bars.

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

Exams that ask this topic