O28
Min Stack Design
Problem Statement & Objective
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time O(1).
Function Signature (Python)
min_stack_operations(operations: list) -> listInput & Output Contract
Output Rule:Sorgu sonuçlarını içeren liste (None, sayı).
System Constraints
1 <= islemler.length <= 3 * 10^4
-2^31 <= val <= 2^31 - 1
pop, top ve getMin çağrıları her zaman boş olmayan yığında yapılırExample Execution Walkthrough
islemler = [['push', -2], ['push', 0], ['push', -3], ['getMin'], ['pop'], ['top'], ['getMin']]
cevap: [None, None, None, -3, None, 0, -2]Example Test Scenarios (3)
Example 1
Input:
[[["push",-2],["push",0],["push",-3],["getMin"],["pop"],["top"],["getMin"]]]Expected Output:
[null,null,null,-3,null,0,-2]Example 2
Input:
[[["push",1],["push",2],["top"],["getMin"]]]Expected Output:
[null,null,2,1]Example 3: Single Element
Input:
[[["push",5],["getMin"]]]Expected Output:
[null,5]