Question
Which statement about Monotonic Stack is the strongest interview answer?
- Monotonic Stack is mostly a naming style choice and has little effect on runtime or design.
- Monotonic Stack exists mainly to reduce the number of Java files in a project.
- Monotonic Stack matters only for frontend frameworks, not for core Java applications.
- A monotonic stack keeps elements in increasing or decreasing order so it can answer next-greater or next-smaller style queries efficiently.
Hint
Start with the core rule behind Monotonic Stack.
Answer and rationale
Correct answer: D. A monotonic stack keeps elements in increasing or decreasing order so it can answer next-greater or next-smaller style queries efficiently.
A monotonic stack keeps elements in increasing or decreasing order so it can answer next-greater or next-smaller style queries efficiently. This is the base concept interviewers commonly test first.
Track: Java