Data Structures & AlgorithmsVery hardGATE CS · Product placement

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

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

Correct answer: D. 8

For every bar, extend to the nearest smaller bar on each side; the best height × width is 8. 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