Im struggling to get the below problem right for a quite a while sometime.
Given an array of ints, is it possible to choose a group of some of the ints, such that the group sums to the given target, with this additional constraint: if there are numbers in the array that are adjacent and the identical value, they must either all be chosen, or none of them chosen. For example, with the array {1, 2, 2, 2, 5, 2}, either all three 2's in the middle must be chosen or not, all as a group. (one loop can be used to find the extent of the identical values).
groupSumClump(0, {8, 2, 2, 1}, 9) → true
groupSumClump(0, {2, 4, 4, 8}, 14) → false
The code is at http://ideone.com/Udk5q
Failing test case scenarios:
groupSumClump(0, {2, 4, 4, 8}, 14) → false -->NegativeArraySizeException
groupSumClump(0, {8, 2, 2, 1}, 9) → true false --> X
i have really tried my best to make it work but alas its failing always. Please Need your help SO experts to resolve this problem I will be highly obliged and thankful to you,if you can spare a few minutes to look into my problem as well and help me in acheieving the desired solution.