title: Need help in figuring out bug in Word Wrap problem DP solution
body: <p>The problem statement is given here : <a href="https://practice.geeksforgeeks.org/problems/word-wrap1646/1#" rel="nofollow noreferrer">https://practice.geeksforgeeks.org/problems/word-wrap1646/1#</a></p>
  <p>This it the solution I came up with.</p>
  <pre><code>class Solution
  {
      public int solveWordWrap (int[] nums, int k)
      {
          return solveWordWrap(0,nums,k);
      }
      
      private int solveWordWrap(int startIndx, int[] nums, int k){
          
          if(startIndx &gt;= nums.length-1)
              return 0;
          
          int min = Integer.MAX_VALUE;
          
          int charCount = 0;
          int words = 0;
          for(int i = startIndx; i &lt; nums.length; i++){
              charCount = charCount + nums[i];
              words++;
              if(charCount+words-1 &lt;= k)
                  min = Math.min( (int)Math.pow(k - (charCount+ words-1),2) + solveWordWrap(i+1,nums,k),min);
              else
                  break;
          }
          
          return min;
      }
  }
  </code></pre>
  <p>For the input</p>
  <pre><code>nums = {10,6,5,3,1,10,8,2}
  k = 12
  </code></pre>
  <p>The correct solution is 45, but my code is outputting 46.</p>
  <p>I am not able to find the error.</p>