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 behavior or design tradeoffs.
- A monotonic stack keeps values or indices in sorted monotonic order so next-greater or next-smaller relationships can be answered efficiently.
- Monotonic Stack exists mainly to reduce the number of files in a Python project.
- Monotonic Stack matters only for frontend scripting and not for backend or automation code.
Hint
Start with the core rule behind Monotonic Stack.
Answer and rationale
Correct answer: B. A monotonic stack keeps values or indices in sorted monotonic order so next-greater or next-smaller relationships can be answered efficiently.
A monotonic stack keeps values or indices in sorted monotonic order so next-greater or next-smaller relationships can be answered efficiently. This is the base concept interviewers commonly test first.
Track: Python