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