Code RoomStack min max queries
MediumPrep Room Coding #1337

Stack min max queries

CodingAlgorithms & data structuresMid–Senior~25 min

Design a stack that, in addition to push and pop, can report the current minimum AND current maximum in O(1) time. Simulate it: given a list of operations where each op is ['push', x], ['pop'], ['min'], or ['max'], return the list of results produced by the 'min' and 'max' queries in order. 'pop' on the described sequence is always valid. Values fit in 32-bit signed integers.

Implement
min_max_stack(ops: list[list]) → list[int]
Examples
in[[["push",5],["push",2],["min"],["max"],["push",8],["max"],["pop"],["max"]]]out[2,5,8,5]
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"],["max"]]][2,5,8,5]not run yetsample