Sla7er's blog

By Sla7er, history, 9 years ago, In English

Can anyone Suggest where my logic failed for this question, here is my solution which passed the example test cases, but when run the system test it gives the verdict as failed, Thank you.

  • Vote: I like it
  • +3
  • Vote: I do not like it

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

I didn't solve this yet, but I think it's pick or leave dynamic programming problem, but you have to one more dimension to know if the first item picked! so the state is as follow:

F(N, picked) = Max(F(N-2, picked), F(N-1, picked)); 
F(0,0) = 0, F(0,1) = donations[0]; 
  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I know it's late but your not right maybe if we pick the first element then it will not be good enough.