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.
- All Contests
- HourRank 7
- Nikita and the Game
- Discussions
Nikita and the Game
Nikita and the Game
Sort by
recency
|
28 Discussions
|
Please Login in order to post a comment
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.
Why does the editorial use dp when the problem does not have any overlapping substructure. My non-dp solution passed easily.
The editorial says " It should be noted that maximum points for a subarray can be calculated by considering only the first valid 'X' for a subarray (rather than by considering all valid 'X')"
how can you prove it?
Editorial code is wrong, if you try this input:
All of sets are the same(items in different order), and you will get 3, 2, 0, output! The code doesn't check all possible partitions:
Also it failse in this case:
It outputs 0, instead of 1, (3,4,6),(5,8) The problem seems to be NP-Hard, so I don't think there is any optimal solution.
Please help me with my code, cant understand where it went wrong - https://www.hackerrank.com/contests/hourrank-7/challenges/array-splitting/submissions/code/5838224
private static int solve(int[] arr, int start, int end, long totalSum) {