Neighbouring Enemy

Sir, in this question we are not considering the forward move ,i.e. we have the option to delete the previous number or the next number but in the editorial, we are only considering the previous number, pls explain how to think, in such cases i.e to completely ignore the next part.

@Vishal_234,
We are not ignoring the next number, we are doing it by bottom up dp, so it means, that we are filling up the dp array, in an order, such that, when we are considering a_i, then there is no number a_i+1 in our subproblem till now, we only have a subproblem, which has numbers <=a_i. Thus we don’t have to worry about a_i+1. and when we will be solving the subproblem a_i+1, we will consider (a_i+1)-1=a_i, thus the case of deleting a_i+1 while deleting a_i would be taken care of now.

Bhaiya…I didn’t understand the second part of your explanation.

Bhaiya, according to this , consider a case where , maximum value of i is calculated by considering it , and then again i+1 is considered by keeping it ,which can’t be possible as by keeping ith value we would have deleted the i+1 value.Please explain this.

@Vishal_234,
Don’t consider it like when we consider i, we delete i+1, and then it is not available, in dp we look at all possible scenarios, just efficiently, thus when we look at i, we consider i+1 doesn’t exist, and when we consider i+1, we can consider removing i, as asked by the problem.
Don’t worry, it is quite of an intuition thing, if you think its too overwhelming to understand now, just leave it. Gradually, after doing more and more dp problems, you will just have an intuition of what I am saying.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.