title: design a stack such that getMinimum( ) should be O(1)
body: <p>This is an interview question.</p>
  <blockquote>
  <p>You need to design a stack which holds an integer value such that <code>getMinimum()</code> function should return the minimum element in the stack.</p>
  <p>For example:</p>
  <blockquote>
  <p>case #1</p>
  <p>5 ← TOP<br />
  1<br />
  4<br />
  6<br />
  2</p>
  <p>When getMinimum() is called it should return 1, which is the minimum element in the stack.</p>
  <p>case #2</p>
  <p><code>stack.pop()</code><br />
  <code>stack.pop()</code></p>
  <p>Note: Both 5 and 1 are popped out of the stack.
  So after this, the stack looks like</p>
  <p>4 ← TOP<br />
  6<br />
  2</p>
  <p>When <code>getMinimum()</code> is called it should return 2 which is the minimum in the stack.</p>
  </blockquote>
  <p><strong>Constraints:</strong></p>
  <ol>
  <li>getMinimum should return the minimum value in O(1)</li>
  <li>Space constraint also has to be considered while designing it and if you use extra space, it should be of constant space.</li>
  </ol>
  </blockquote>