https://leetcode.com/problems/min-stack/description/?envType=study-plan-v2&envId=top-interview-150

class MinStack {
public:
    vector<pair<int, int>> st;
    MinStack() {
        
    }
    
    void push(int val) {
        if (st.size()) {
            st.push_back({val, min(val, st.back().second)});
        } else {
            st.push_back({val, val});
        }
    }
    
    void pop() {
        st.pop_back();
    }
    
    int top() {
        return st.back().first;
    }
    
    int getMin() {
        return st.back().second;
    }
};

Time Complexity: O(n)
O(1) time complexity for each function.
Space: O(n)