Code RoomMin-max stack
MediumPrep Room Coding #1145

Min-max stack

CodingDatabases & SQLAlgorithms & data structuresMid–Senior~25 min

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.

0:00 of about 25 min
InputExpectedGot
[[["push",5],["push",2],["min"],["max"],["push",8],["max"],["pop"],["min"]]][2,5,8,8,2]not run yetsample