title: How to repair SigSegV
body: <p>I was doing a problem where you need to find the best K figures to eliminate from N so the number would have the minimum difference between the smallest and highest figure.</p>
  
  <pre><code>#include&lt;bits/stdc++.h&gt;
  
  using namespace std;
  
  int diff(vector &lt;int&gt; x){
      sort(x.begin(),x.end());
      return x.back()-x[0];
  }
  
  int diffMin(vector&lt;int&gt; x,int h,int best){
     if(h==0) return diff(x);
     else{
         for(int a=0;a&lt;x.size();a++){
             int y=x[a];
             x.erase(x.begin()+a);
             best=min(best,diffMin(x,h-1,best));
             x.insert(x.begin()+a,y);
         }
     return best;
     }
  }
  
  int main(){
      int n,k;
      cin&gt;&gt;n&gt;&gt;k;
      vector &lt;int&gt; x;
      while(n!=0){
          x.push_back(n%10);
          n/=10;
      }
      cout&lt;&lt;diffMin(x,k,10);
  }
  </code></pre>
  
  <p>I put it in an evaluator but it said "Caught fatal signal 11(SigSegV )". Could someone explain me why?</p>