Is my approach correct? why are any test cases not passing
- The problem isn’t asking you to take %MOD, then why are you.
- You cannot go to i=i+2 if i=n-1;
- It is not necessary to go till the very right end of the array, we can start the backwards journey if we will not profit going right anymore.
Try running you code on this,
Input:
5 2
5 3 -2 1 -1
Output: 9