title: Dynamic Programming (Codility Q: NumberSolitaire)
body: <p>This is the question:
  codility.com/programmers/task/number_solitaire</p>
  
  <p>and below link is my result (50% from Codility):
  <a href="https://codility.com/demo/results/training8AMJZH-RTA/" rel="noreferrer">https://codility.com/demo/results/training8AMJZH-RTA/</a></p>
  
  <p>My code (at the first, I tried to solve this problem using Kadane's Algo):</p>
  
  <pre><code>class Solution {
      public int solution(int[] A) {
          int temp_max = Integer.MIN_VALUE;
          int max = 0;
          int k = 1;
  
          if(A.length == 2) return A[0] + A[A.length-1];
  
          for(int i = 1; i &lt; A.length-1; i++) {
              if(temp_max &lt; A[i]) temp_max = A[i];
  
              if(A[i] &gt; 0) {
                  max += A[i];
                  temp_max = Integer.MIN_VALUE;
                  k = 0;           
  
              } else if(k % 6 == 0) {
                  max += temp_max;
                  temp_max = Integer.MIN_VALUE;
                  k = 0;
              }
              k++;
          }
          return A[0] + max + A[A.length-1];
      }
  </code></pre>
  
  <p>And below is the solution (100% from Codility result) that I found from web: </p>
  
  <pre><code>class Solution {
      public int solution(int[] A) {
          int[] store = new int[A.length];
          store[0] = A[0];
          for (int i = 1; i &lt; A.length; i++) {
              store[i] = store[i-1];
              for (int minus = 2; minus &lt;= 6; minus++) {
                  if (i &gt;= minus) {
                      store[i] = Math.max(store[i], store[i - minus]);
                  } else {
                      break;
                  }
              }
              store[i] += A[i];
          }
          return store[A.length - 1];
      }
  }
  </code></pre>
  
  <p>I have no idea what is the problem with my code:(</p>
  
  <p>I tried several test cases but, nothing different with the solution &amp; my code </p>
  
  <p>but, codility test result shows mine is not perfectly correct.
  (<a href="https://codility.com/demo/results/training8AMJZH-RTA/" rel="noreferrer">https://codility.com/demo/results/training8AMJZH-RTA/</a>)</p>
  
  <p>please anyone explain me the problem with my code~~</p>