🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Monotonic Stack: all 13 questions

Quiz: Monotonic Stack · Question 7 of 13

In the largest-rectangle solution, what is the extra 0 added at the end for?

In the largest-rectangle solution, what is the extra 0 added at the end for?

  1. A.To avoid an empty array error
  2. B.To pop and measure every bar still on the stack
  3. C.To make the heights increasing
  4. D.It is the answer for an empty histogram only
Answer & explanation

Correct answer: To pop and measure every bar still on the stack

A height-0 bar is smaller than everything, so it forces all remaining bars off the stack.

Can you get the rest right without peeking?

Take the timed Quiz: Monotonic Stack quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →