issahaddar5's blog

By issahaddar5, history, 9 years ago, In English

I am trying to solve this problem. However, I am getting a wrong answer on test case 11 and I can't figure it out. This is my code

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
9 years ago, # |
  Vote: I like it 0 Vote: I do not like it

The formula that can solve the problem is:

dp[i] = max(dp[i-1], dp[i-3] + a[i]);

Base Case: dp[0] = dp[1] = dp[2] = 0;

So you can start the loop from 3 to N+2.

The answer is :dp[N+2]