• + 1 comment

    c++ vector getMax(vector operations) { vector result; stack stk; stack maxStack;

    for (string op : operations) {
        stringstream ss(op);
        int command, value;
        ss >> command;
    
        if (command == 1) {
            ss >> value;
            stk.push(value);
            if (maxStack.empty() || value >= maxStack.top()) {
                maxStack.push(value);
            }
        } else if (command == 2) {
            if (!stk.empty()) {
                if (stk.top() == maxStack.top()) {
                    maxStack.pop();
                }
                stk.pop();
            }
        } else if (command == 3) {
            if (!maxStack.empty()) {
                result.push_back(maxStack.top());
            }
        }
    }
    
    return result;
    

    }