title: Retrieving the Min element in a stack in O(1) Time
body: <p>The reason I'm asking this question is because I cannot see why the way I think cannot be applied to this particular question</p>
  
  <p><i>"How would you design a stack which, 
  in addition to push and pop, also has a function min which returns the minimum element? Push, pop and min should all operate in O(1) time</i>"</p>
  
  <p><b>My basic solution: </b>Wouldn't it be possible if we had a variable in <b>stack</b> class, that whenever we were pushing an item to stack we would check if it is <b>smaller</b> than our <b>min</b> variable. If it is assign the value to the min, if not ignore.</p>
  
  <p>You would still get the O(1) as the min function would be;</p>
  
  <pre><code>int getMinimum(){
    return min;
  }
  </code></pre>
  
  <p>Why this solution is never mentioned, or what is the fault with the way I think?</p>