Can someone please point out a corner case? I have created a separate array S, where I store the max sum up till a number A[i], with A[i] included. Therefore, my logical statement becomes S[i] = max(A[i] + S[i-2], A[i] + S[i-1])
In the end, I see which of S[i] and S[i-1] is bigger.
Problem - http://www.spoj.com/problems/FARIDA/ Code - http://ideone.com/F2BSGX