Python: Which statement about Monotonic Stack is the strongest interview answer?

Difficulty:

Easy

Questions:

1

Time Limit:

2 minutes

Passing Score:

100%

Question

Which statement about Monotonic Stack is the strongest interview answer?

  1. Monotonic Stack is mostly a naming style choice and has little effect on runtime behavior or design tradeoffs.
  2. A monotonic stack keeps values or indices in sorted monotonic order so next-greater or next-smaller relationships can be answered efficiently.
  3. Monotonic Stack exists mainly to reduce the number of files in a Python project.
  4. 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