You are tasked with implementing a stack that supports the following operations while handling up to q queries:
You will receive a series of queries, and each query will perform one of the following actions:
Example 1
Input: q = 4, queries = [(1, 5), (1, 7), (3), (2)]
Output: 5, 7
Explanation: push(5): Add 5 to the stack. Stack becomes {5}. push(7): Add 7 to the stack. Stack becomes {5, 7}. getMin(): The smallest element in the stack is 5.
Output: 5. pop(): Remove and return the top element (7). Stack becomes {5}.
Output: 7.
Example 2
Input: q = 5, queries = [(1, 10), (2), (3), (2), (3)]
Output: 10, -1, -1, -1
Explanation: push(10): Add 10 to the stack. Stack becomes {10}. pop(): Remove and return the top element (10). Stack becomes (empty).
Output: 10. getMin(): The stack is empty, so return -1.
Output: -1. pop(): The stack is empty, so return -1.
Output: -1. getMin(): The stack is empty, so return -1.
Output: -1.
Sign in to write, run, and submit your solution against the full test suite.