> For the complete documentation index, see [llms.txt](https://chiragjain.gitbook.io/neetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://chiragjain.gitbook.io/neetcode/155-min-stack/code.md).

# CODE

```python
class MinStack:

    def __init__(self):
        self.stack = deque()
        self.curr_min = float('inf')
        

    def push(self, val: int) -> None:
        self.stack.append((val, self.curr_min))
        self.curr_min = min(self.curr_min, val)
        

    def pop(self) -> None:
        _, self.curr_min = self.stack.pop()
        

    def top(self) -> int:
        return self.stack[-1][0]
        

    def getMin(self) -> int:
        return self.curr_min
        


# Your MinStack object will be instantiated and called as such:
# obj = MinStack()
# obj.push(val)
# obj.pop()
# param_3 = obj.top()
# param_4 = obj.getMin()
```
