← 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?
- A.To avoid an empty array error
- B.To pop and measure every bar still on the stack
- C.To make the heights increasing
- 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 →