Code Room
CodingMediumcod-g578
Subject StacksLevel Mid–Senior~25 minCommon in Databases & SQL · Algorithms & data structures interviewsIndustries Software development

Question

Implement a stack that supports push(x), pop(), and two O(1) queries: get_min() returning the minimum of all elements currently on the stack, and get_max() returning the maximum. Replay a list of operations; each op is ["push", x], ["pop"], ["min"], or ["max"]. Return the list of results produced by pop/min/max ops in order (pop returns the popped value). Assume min/max/pop are never called on an empty stack.

Implement
minmax_stack(ops: list[list]) → list[int]
Examples
in[[["push",5],["push",2],["min"],["max"],["push",8],["max"],["pop"],["min"]]]out[2,5,8,8,2]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.