Data Structures & AlgorithmsVery hardGATE CS · Product placement

Bars of width 1 have heights [5, 5, 7, 8, 6, 5, 2, 8]. What is the area of the largest rectangle that fits under the histogram (computed with a stack of increasing heights)?

  1. A. 29
  2. B. 16
  3. C. 8
  4. D. 30

Correct answer: D. 30

For every bar, extend to the nearest smaller bar on each side; the best height × width is 30. The tallest bar alone or the full-width minimum strip are smaller.

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

Exams that ask this topic