All problems
Min Stack Min Change Count
Problem
Simulate a stack with O(1) minimum tracking. operations contains "push", "pop", or "get_min"; values supplies the pushed value and is ignored otherwise. Return [min_change_count, results] where min_change_count counts pushes that set a new strict minimum (the first push counts) and results collects each get_min value (None when the stack is empty).
Hint
Keep a parallel minimum stack: each entry is the minimum of everything pushed so far.
Test cases
case 1
in: [["push","push","get_min","push","get_min","pop","get_min"],[3,5,0,2,0,0,0]]
expected: [2,[3,2,3]]
case 2
in: [["push","push","get_min","pop","get_min","pop","get_min"],[1,1,0,0,0,0,0]]
expected: [1,[1,1,null]]
case 3
in: [[],[]]
expected: [0,[]]
case 4
in: [["get_min","pop"],[0,0]]
expected: [0,[null]]
Starter codePython
def min_stack_changes(operations, values):
# Your code here
pass4 test cases · run your code against them in the editor