For 1 3 5 9 2, it should be 1+5+9=15

I understand the basic approach (which I think is optimal). However, I'm facing some problems in its code implementation.

Basically, store at each point the max answer such that:

1. Last element was picked

2. Last was not, second last was picked

3. None of the previous two were picked

Well, nevermind now, I solved it.

However, if you still want to try:

(3+3+3+5+3)

(10+3+7+3)