title: Minimum operation to make an array good
body: <p>You are given an array A containing N integers. You are also given an integer K. An array is good if <code>A[i]&lt;=A[i + k]</code>, <code>i = 1, 2, 3,.., n - k</code>
  In one operation, you can choose any element and convert it to an arbitrary integer.</p>
  <p><strong>Task</strong></p>
  <p>Determine the minimum number of operations to make the array good.
  Note: Assume 1-based indexing.</p>
  <p><strong>What I tried</strong></p>
  <pre class="lang-cpp prettyprint-override"><code>int lis(std::vector&lt;int&gt;&amp; a){
  
      if(a.size() == 0) return 0;
  
      vector&lt;int&gt; b;
  
      b.push_back(a[0]);
  
      for(int i = 1; i &lt; a.size(); i++){
  
          if(b.back() &lt;= a[i]) b.push_back(a[i]);
  
          else{
  
              int idx = lower_bound(b.begin(), b.end(), a[i]) - b.begin();
  
              b[idx] = a[I];
  
          }
  
      }
  
      return b.size();
  
  }
  
  
  int minOperations(int n, vector&lt;int&gt; a, int k){
  
      int cost = 0;
  
      for(int i = 0; i &lt; k; i++){
  
          vector&lt;int&gt; b;
  
          for(int j = i; j &lt; n; j+=k) {
  
              b.push_back(a[j]);
  
          }
  
          cost += b.size() - lis(b);
  
      }
  
      return cost;
  }
  </code></pre>
  <p><em>It is partially correct</em></p>