Data Structures & AlgorithmsHardGATE CS · TCS NQT

For the histogram [2, 1, 2], each bar i has a maximal rectangle width w_i: the number of consecutive bars around i (including i) that are at least as tall as bar i. What is the sum of the w_i?

  1. A. 6
  2. B. 5
  3. C. 4
  4. D. 7

Correct answer: B. 5

Bar 0 has width 1, bar 1 spans all three bars (width 3) and bar 2 has width 1, so the total is 5.

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

Exams that ask this topic