{"id":"6b093ddfbd4755deb67ee089","slug":"min-stack","title":"Stack with O(1) minimum","summary":"Design a stack that, besides push, pop and top, returns its smallest element in constant time. A question about the memory–time trade-off.","servedLang":"en","availableLangs":["pl","en"],"kind":"code","category":"algorithms","status":"published","difficulty":"easy","topics":[],"techs":["typescript","javascript","python","dotnet","java","go"],"tags":["stack","design","data-structures"],"languages":[{"lang":"typescript","runner":"browser","starter":"class MinStack {\n  /** Pushes x. */\n  push(x: number): void {\n    throw new Error('Not implemented');\n  }\n\n  /** Removes and returns the top element; Error('Stack is empty') when empty. */\n  pop(): number {\n    throw new Error('Not implemented');\n  }\n\n  /** Returns the top element; Error('Stack is empty') when empty. */\n  top(): number {\n    throw new Error('Not implemented');\n  }\n\n  /** Returns the smallest element; Error('Stack is empty') when empty. */\n  getMin(): number {\n    throw new Error('Not implemented');\n  }\n\n  get size(): number {\n    throw new Error('Not implemented');\n  }\n}\n","testCount":6,"tests":"test('top and getMin after pushes', () => {\n  const s = new MinStack();\n  s.push(5);\n  s.push(3);\n  s.push(7);\n  expect(s.top()).toBe(7);\n  expect(s.getMin()).toBe(3);\n  expect(s.size).toBe(3);\n});\n\ntest('pop returns the value and restores the previous minimum', () => {\n  const s = new MinStack();\n  [5, 3, 7, 2].forEach((x) => s.push(x));\n  expect(s.getMin()).toBe(2);\n  expect(s.pop()).toBe(2);\n  expect(s.getMin()).toBe(3);\n  expect(s.pop()).toBe(7);\n  expect(s.getMin()).toBe(3);\n  expect(s.pop()).toBe(3);\n  expect(s.getMin()).toBe(5);\n  expect(s.size).toBe(1);\n});\n\ntest('repeated minimums', () => {\n  const s = new MinStack();\n  [2, 2, 1, 1].forEach((x) => s.push(x));\n  s.pop();\n  expect(s.getMin()).toBe(1);\n  s.pop();\n  expect(s.getMin()).toBe(2);\n  s.pop();\n  expect(s.getMin()).toBe(2);\n});\n\ntest('negative values', () => {\n  const s = new MinStack();\n  [-1, -5, 4, -5].forEach((x) => s.push(x));\n  expect(s.getMin()).toBe(-5);\n  s.pop();\n  expect(s.getMin()).toBe(-5);\n  s.pop();\n  s.pop();\n  expect(s.getMin()).toBe(-1);\n});\n\ntest('empty stack throws', () => {\n  const s = new MinStack();\n  expect(s.size).toBe(0);\n  expect(() => s.pop()).toThrow('Stack is empty');\n  expect(() => s.top()).toThrow('Stack is empty');\n  expect(() => s.getMin()).toThrow('Stack is empty');\n  s.push(1);\n  s.pop();\n  expect(() => s.getMin()).toThrow('Stack is empty');\n});\n\ntest('performance: 100 000 operations of each kind', () => {\n  const s = new MinStack();\n  const n = 100000;\n  let checksum = 0;\n  for (let i = 0; i < n; i++) {\n    s.push(n - i);\n    checksum += s.getMin();\n  }\n  for (let i = 0; i < n; i++) {\n    checksum += s.getMin() + s.pop();\n  }\n  expect(s.size).toBe(0);\n  expect(checksum).toBe(3 * (n * (n + 1)) / 2);\n});\n"},{"lang":"javascript","runner":"browser","starter":"class MinStack {\n  /** Pushes x. */\n  push(x) {\n    throw new Error('Not implemented');\n  }\n\n  /** Removes and returns the top element; Error('Stack is empty') when empty. */\n  pop() {\n    throw new Error('Not implemented');\n  }\n\n  /** Returns the top element; Error('Stack is empty') when empty. */\n  top() {\n    throw new Error('Not implemented');\n  }\n\n  /** Returns the smallest element; Error('Stack is empty') when empty. */\n  getMin() {\n    throw new Error('Not implemented');\n  }\n\n  get size() {\n    throw new Error('Not implemented');\n  }\n}\n","testCount":6,"tests":"test('top and getMin after pushes', () => {\n  const s = new MinStack();\n  s.push(5);\n  s.push(3);\n  s.push(7);\n  expect(s.top()).toBe(7);\n  expect(s.getMin()).toBe(3);\n  expect(s.size).toBe(3);\n});\n\ntest('pop returns the value and restores the previous minimum', () => {\n  const s = new MinStack();\n  [5, 3, 7, 2].forEach((x) => s.push(x));\n  expect(s.getMin()).toBe(2);\n  expect(s.pop()).toBe(2);\n  expect(s.getMin()).toBe(3);\n  expect(s.pop()).toBe(7);\n  expect(s.getMin()).toBe(3);\n  expect(s.pop()).toBe(3);\n  expect(s.getMin()).toBe(5);\n  expect(s.size).toBe(1);\n});\n\ntest('repeated minimums', () => {\n  const s = new MinStack();\n  [2, 2, 1, 1].forEach((x) => s.push(x));\n  s.pop();\n  expect(s.getMin()).toBe(1);\n  s.pop();\n  expect(s.getMin()).toBe(2);\n  s.pop();\n  expect(s.getMin()).toBe(2);\n});\n\ntest('negative values', () => {\n  const s = new MinStack();\n  [-1, -5, 4, -5].forEach((x) => s.push(x));\n  expect(s.getMin()).toBe(-5);\n  s.pop();\n  expect(s.getMin()).toBe(-5);\n  s.pop();\n  s.pop();\n  expect(s.getMin()).toBe(-1);\n});\n\ntest('empty stack throws', () => {\n  const s = new MinStack();\n  expect(s.size).toBe(0);\n  expect(() => s.pop()).toThrow('Stack is empty');\n  expect(() => s.top()).toThrow('Stack is empty');\n  expect(() => s.getMin()).toThrow('Stack is empty');\n  s.push(1);\n  s.pop();\n  expect(() => s.getMin()).toThrow('Stack is empty');\n});\n\ntest('performance: 100 000 operations of each kind', () => {\n  const s = new MinStack();\n  const n = 100000;\n  let checksum = 0;\n  for (let i = 0; i < n; i++) {\n    s.push(n - i);\n    checksum += s.getMin();\n  }\n  for (let i = 0; i < n; i++) {\n    checksum += s.getMin() + s.pop();\n  }\n  expect(s.size).toBe(0);\n  expect(checksum).toBe(3 * (n * (n + 1)) / 2);\n});\n"},{"lang":"python","runner":"browser","starter":"class MinStack:\n    def push(self, x: int) -> None:\n        raise NotImplementedError\n\n    def pop(self) -> int:\n        \"\"\"Removes and returns the top element; IndexError when empty.\"\"\"\n        raise NotImplementedError\n\n    def top(self) -> int:\n        \"\"\"Returns the top element; IndexError when empty.\"\"\"\n        raise NotImplementedError\n\n    def get_min(self) -> int:\n        \"\"\"Returns the smallest element; IndexError when empty.\"\"\"\n        raise NotImplementedError\n\n    def __len__(self) -> int:\n        raise NotImplementedError\n","testCount":6,"tests":"def eq(got, expected, what):\n    assert got == expected, f\"{what}: expected {expected}, got {got}\"\n\n\ndef test_top_and_get_min_after_pushes():\n    s = MinStack()\n    for x in (5, 3, 7):\n        s.push(x)\n    eq(s.top(), 7, \"top()\")\n    eq(s.get_min(), 3, \"get_min()\")\n    eq(len(s), 3, \"len()\")\n\n\ndef test_pop_restores_previous_minimum():\n    s = MinStack()\n    for x in (5, 3, 7, 2):\n        s.push(x)\n    eq(s.get_min(), 2, \"get_min()\")\n    eq(s.pop(), 2, \"pop()\")\n    eq(s.get_min(), 3, \"get_min() after popping 2\")\n    eq(s.pop(), 7, \"pop()\")\n    eq(s.get_min(), 3, \"get_min() after popping 7\")\n    eq(s.pop(), 3, \"pop()\")\n    eq(s.get_min(), 5, \"get_min() after popping 3\")\n    eq(len(s), 1, \"len()\")\n\n\ndef test_repeated_minimums():\n    s = MinStack()\n    for x in (2, 2, 1, 1):\n        s.push(x)\n    s.pop()\n    eq(s.get_min(), 1, \"get_min() after one pop\")\n    s.pop()\n    eq(s.get_min(), 2, \"get_min() after two pops\")\n    s.pop()\n    eq(s.get_min(), 2, \"get_min() after three pops\")\n\n\ndef test_negative_values():\n    s = MinStack()\n    for x in (-1, -5, 4, -5):\n        s.push(x)\n    eq(s.get_min(), -5, \"get_min()\")\n    s.pop()\n    eq(s.get_min(), -5, \"get_min() after one pop\")\n    s.pop()\n    s.pop()\n    eq(s.get_min(), -1, \"get_min() after three pops\")\n\n\ndef test_empty_stack_raises():\n    s = MinStack()\n    eq(len(s), 0, \"len() of a new stack\")\n    with raises(IndexError):\n        s.pop()\n    with raises(IndexError):\n        s.top()\n    with raises(IndexError):\n        s.get_min()\n    s.push(1)\n    s.pop()\n    with raises(IndexError):\n        s.get_min()\n\n\ndef test_performance_100k_operations():\n    s = MinStack()\n    n = 100_000\n    checksum = 0\n    for i in range(n):\n        s.push(n - i)\n        checksum += s.get_min()\n    for _ in range(n):\n        checksum += s.get_min() + s.pop()\n    eq(len(s), 0, \"len() at the end\")\n    eq(checksum, 3 * n * (n + 1) // 2, \"checksum\")\n"},{"lang":"csharp","runner":"judge0","starter":"using System;\n\npublic class MinStack\n{\n    public void Push(int x)\n    {\n        throw new NotImplementedException();\n    }\n\n    /// <summary>Removes and returns the top element; InvalidOperationException when empty.</summary>\n    public int Pop()\n    {\n        throw new NotImplementedException();\n    }\n\n    /// <summary>Returns the top element; InvalidOperationException when empty.</summary>\n    public int Top()\n    {\n        throw new NotImplementedException();\n    }\n\n    /// <summary>Returns the smallest element; InvalidOperationException when empty.</summary>\n    public int GetMin()\n    {\n        throw new NotImplementedException();\n    }\n\n    public int Count\n    {\n        get { throw new NotImplementedException(); }\n    }\n}\n","testCount":6},{"lang":"java","runner":"judge0","starter":"class MinStack {\n    void push(int x) {\n        throw new UnsupportedOperationException(\"Not implemented\");\n    }\n\n    /** Removes and returns the top element; IllegalStateException when empty. */\n    int pop() {\n        throw new UnsupportedOperationException(\"Not implemented\");\n    }\n\n    /** Returns the top element; IllegalStateException when empty. */\n    int top() {\n        throw new UnsupportedOperationException(\"Not implemented\");\n    }\n\n    /** Returns the smallest element; IllegalStateException when empty. */\n    int getMin() {\n        throw new UnsupportedOperationException(\"Not implemented\");\n    }\n\n    int size() {\n        throw new UnsupportedOperationException(\"Not implemented\");\n    }\n}\n","testCount":6},{"lang":"go","runner":"judge0","starter":"package main\n\ntype MinStack struct {\n\t// TODO\n}\n\nfunc NewMinStack() *MinStack {\n\treturn &MinStack{}\n}\n\n// Push pushes x.\nfunc (s *MinStack) Push(x int) {\n\tpanic(\"not implemented\")\n}\n\n// Pop removes and returns the top element; ok is false when the stack is empty.\nfunc (s *MinStack) Pop() (value int, ok bool) {\n\tpanic(\"not implemented\")\n}\n\n// Top returns the top element; ok is false when the stack is empty.\nfunc (s *MinStack) Top() (value int, ok bool) {\n\tpanic(\"not implemented\")\n}\n\n// Min returns the smallest element; ok is false when the stack is empty.\nfunc (s *MinStack) Min() (value int, ok bool) {\n\tpanic(\"not implemented\")\n}\n\nfunc (s *MinStack) Len() int {\n\tpanic(\"not implemented\")\n}\n","testCount":6}],"questionCount":null,"xp":10,"stats":{"attempts":0,"solves":0,"solutions":0,"comments":0},"solveRate":null,"publishedAt":"2026-11-27T08:22:55.005Z","requestedLang":"en","statement":{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"An editor with undo history keeps values on a stack and keeps asking for the "},{"type":"text","text":"smallest","marks":[{"type":"bold"}]},{"type":"text","text":" one. Scanning the whole stack each time is too slow – we need a "},{"type":"text","text":"MinStack","marks":[{"type":"code"}]},{"type":"text","text":" where "},{"type":"text","text":"every","marks":[{"type":"bold"}]},{"type":"text","text":" operation runs in O(1)."}]},{"type":"heading","attrs":{"level":2,"id":"task"},"content":[{"type":"text","text":"Task"}]},{"type":"table","content":[{"type":"tableRow","content":[{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Operation"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Behaviour"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"push(x)","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"pushes the integer "},{"type":"text","text":"x","marks":[{"type":"code"}]}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"pop()","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"removes and "},{"type":"text","text":"returns","marks":[{"type":"bold"}]},{"type":"text","text":" the top element"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"top()","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"returns the top element without removing it"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"getMin()","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"returns the smallest element on the stack"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"size","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"number of elements"}]}]}]}]},{"type":"paragraph","content":[{"type":"text","text":"pop","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"top","marks":[{"type":"code"}]},{"type":"text","text":" and "},{"type":"text","text":"getMin","marks":[{"type":"code"}]},{"type":"text","text":" on an empty stack report an error:"}]},{"type":"table","content":[{"type":"tableRow","content":[{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Language"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Names"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Empty stack"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"JS/TS"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"push","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"pop","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"top","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"getMin","marks":[{"type":"code"}]},{"type":"text","text":", getter "},{"type":"text","text":"size","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Error('Stack is empty')","marks":[{"type":"code"}]}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Python"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"push","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"pop","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"top","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"get_min","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"len(stack)","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"IndexError","marks":[{"type":"code"}]}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"C#"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Push","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"Pop","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"Top","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"GetMin","marks":[{"type":"code"}]},{"type":"text","text":", property "},{"type":"text","text":"Count","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"InvalidOperationException","marks":[{"type":"code"}]}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Java"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"push","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"pop","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"top","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"getMin","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"size()","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"IllegalStateException","marks":[{"type":"code"}]}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Go"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"NewMinStack()","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"Push","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"Pop","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"Top","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"Min","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"Len","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"second result "},{"type":"text","text":"ok == false","marks":[{"type":"code"}]}]}]}]}]},{"type":"heading","attrs":{"level":2,"id":"example"},"content":[{"type":"text","text":"Example"}]},{"type":"table","content":[{"type":"tableRow","content":[{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Operations"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Result"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"push(5)","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"push(3)","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"push(7)","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"top() = 7","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"getMin() = 3","marks":[{"type":"code"}]}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"push(2)","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"getMin() = 2","marks":[{"type":"code"}]}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"pop()","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"returns "},{"type":"text","text":"2","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"getMin() = 3","marks":[{"type":"code"}]}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"pop()","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"pop()","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"return "},{"type":"text","text":"7","marks":[{"type":"code"}]},{"type":"text","text":" and "},{"type":"text","text":"3","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"getMin() = 5","marks":[{"type":"code"}]}]}]}]}]},{"type":"heading","attrs":{"level":2,"id":"constraints"},"content":[{"type":"text","text":"Constraints"}]},{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Up to 100,000 operations per test, values in the 32-bit "},{"type":"text","text":"int","marks":[{"type":"code"}]},{"type":"text","text":" range."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"The minimum can repeat (e.g. "},{"type":"text","text":"push(1)","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"push(1)","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"pop()","marks":[{"type":"code"}]},{"type":"text","text":" – the minimum is still 1)."}]}]}]},{"type":"heading","attrs":{"level":2,"id":"expected-complexity"},"content":[{"type":"text","text":"Expected complexity"}]},{"type":"paragraph","content":[{"type":"text","text":"Every operation "},{"type":"text","text":"O(1)","marks":[{"type":"bold"}]},{"type":"text","text":", "},{"type":"text","text":"O(n)","marks":[{"type":"bold"}]},{"type":"text","text":" memory."}]}]},"hints":[],"hintsCount":3,"quiz":null,"solutionNotes":null,"unlocked":false,"external":[{"provider":"leetcode","url":"https://leetcode.com/problems/min-stack/","title":"LeetCode 155 – Min Stack","difficulty":null}],"articles":[],"topicsInfo":[],"author":{"id":"6b08bd2e80884893657cc8cf","name":"Redakcja Art of Devs","avatar":null,"handle":"redakcja","community":false},"capabilities":{"judge0":false,"aiReview":false},"createdAt":"2026-11-27T08:22:55.007Z","updatedAt":"2026-11-27T08:22:55.007Z"}