title: Signed Integer Overflow[C++]
body: <p><strong>Objective</strong> Find minimum value in stack in O(1) time complexity.</p>
  <p><strong>Issue</strong> :
  Failing at the below operation (2*x-minEle) in some Leetcode testcases.</p>
  <p><strong>Actual Error</strong> -  runtime error: signed integer overflow: 2 * -2147483648 cannot be represented in type 'int'</p>
  <p>I tried replacing every integer value with long long datatype but still getting the same error</p>
  <p><strong>Following is the code</strong>:</p>
  <pre><code>class MinStack {
  public:
      int minEle = INT_MAX;
      vector&lt;int&gt; s;
      void push(int x) {
          if(s.empty())
          {
              minEle=x;
              s.push_back(x);
              return;
          }
          if(x&lt;minEle)
          {
              s.push_back(2*x-minEle);
              minEle = x;
          }
          else
              s.push_back(x);    
      }
      
      void pop() {
          int y = s.back();
          if(y&lt;minEle)
          {
              minEle = 2*minEle - y;
          }
          s.pop_back();
      }
      
      int top() {
          return s.back();
      }
      
      int getMin() {
          return minEle;
      }
  };
  </code></pre>