564 A codeforces problem

Not able to understand how we are using binary search here?

@toshitvarshney11
As you can understand from the video lecture, that their will be 2 types of cases.

  1. When their is a sequence start from 1 till some i is present at the end of the pile, then that case you can handle separately.
  2. For other cases we know is that we first have to remove some elements from pile then start putting them so the answer will be greater than n.
    So in this case we need to check for every integer i, it is present at positions till x+1+i starting. where x is our mid value you can say, here we need to check the possibility if we select some x, then is it possible that all the elements are present with in that positions range.

If you are facing diffculty in understanding these cases, I will suggest you to please rewatch the video again and then try coding it. Also try to draw some sample test cases on a paper.

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.