We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Nikita and the Game
You are viewing a single comment's thread. Return to all 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.