🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← All topics

Quiz: Monotonic Stack: questions with answers

13 questions, each with the answer and a short explanation.

Take the timed quiz + get a certificate →
  1. Q1. What does this print? (code)
  2. Q2. For "next greater element", the stack (from bottom to top) is always:
  3. Q3. Why is the monotonic stack solution O(n) even with a while loop inside a for loop?
  4. Q4. Why push indexes instead of values onto the stack?
  5. Q5. Which change turns "next greater" into "next smaller"?
  6. Q6. What does dailytemperatures([30, 40, 50, 60]) return?
  7. Q7. In the largest-rectangle solution, what is the extra 0 added at the end for?
  8. Q8. In Java, which type is recommended for a stack?
  9. Q9. What does this print? (code)
  10. Q10. After the loop, what do the indexes still left on the "next greater" stack mean?
  11. Q11. What does this print? (code)
  12. Q12. In the largest rectangle in a histogram, how wide can the rectangle that uses bar i's full height be?
  13. Q13. "For each day, how many consecutive days up to today had a price ≤ today's price?" (the stock span problem). Which tool fits?