Nikita and the Game

  • + 0 comments

    Why consider only first valid partition?

    From the constraint that the numbers in the sequence are greater than or equal to 0 ( note that it has no negative numbers), we can see that the only way a subarray can be partitioned such that it has more than one valid 'X' is by including some zeros as suffix of first half of the partition or prefix of second half of the partition.

    eg-{1,4,3,0,0,0,0,2,3,3}

    X can be anything from 3 to 6. So in effect you only need to consider only 3,any other partition would also yield the same result in effect.

    I think some people got confused because they did not check the constraints and thought the numbers could be negative as well.

    Also the order of the numbers do not change. Some people are trying to solve a completely different problem by reordering the numbers.