O( 1 )✅ | C++ (Step by step explanation)
Intuition\nThe MinStack is a data structure that allows for efficient retrieval of the minimum value in a stack at any given moment. The idea behind this is to 
# Intuition\nThe MinStack is a data structure that allows for efficient retrieval of the minimum value in a stack at any given moment. The idea behind this is to maintain two stacks: one to store the actual elements (in the `arr` stack) and another to store the minimum elements at each step (in the `min_arr` stack).\n\n# Approach\n1. Initialize two stacks, `arr` to store the actual elements and `min_arr` to store the minimum elements.\n2. When pushing an element into the stack:\n   - Push the element into the `arr` stack.\n   - Check if the `min_arr` stack is not empty. If it is, simply push the element into the `min_arr` stack.\n   - If the `min_arr` stack is not empty, calculate the minimum between the current element and the top of the `min_arr` stack and push the minimum value into the `min_arr` stack. This ensures that `min_arr` always contains the minimum value for the stack.\n3. When popping an element from the stack:\n   - Pop the element from both the `arr` and `min_arr` stacks. This maintains the consistency of the two stacks.\n4. To get the top element of the stack, simply return the top element from the `arr` stack.\n5. To get the minimum value of the stack, return the top element from the `min_arr` stack. This provides a constant time operation for retrieving the minimum.\n\n# Complexity\n- Time complexity:\n   - Push: O(1)\n   - Pop: O(1)\n   - Top: O(1)\n   - GetMin: O(1)\n- Space complexity: O(n), where n is the number of elements in the stack.\n\n\n# Code\n```\nclass MinStack {\npublic:\n    stack<int> arr , min_arr ;\n\n    MinStack() {\n        \n    }\n    \n    void push(int val) {\n        arr.push(val) ;\n        if(!min_arr.empty()){\n            val = min (val , min_arr.top()) ; ;\n        }\n\n        min_arr.push(val) ;  \n    }\n    \n    void pop() {\n        arr.pop() ;\n        min_arr.pop() ;\n    }\n    \n    int top() {\n        return arr.top() ;\n    }\n    \n    int getMin() {\n        return min_arr.top() ;\n        \n    }\n};\n\n/**\n * Your MinStack object will be instantiated and called as such:\n * MinStack* obj = new MinStack();\n * obj->push(val);\n * obj->pop();\n * int param_3 = obj->top();\n * int param_4 = obj->getMin();\n */\n```\n\n# Please upvote the solution if you understood it.\n![1_3vhNKl1AW3wdbkTshO9ryQ.jpg](https://assets.leetcode.com/users/images/60d7db71-052d-41b3-aacb-8cb1ed95edbc_1697646629.1901906.jpeg)\n
['Stack', 'C++']