Given an array A of positive elements, you have to flip the sign of some of its elements such that the resultant sum of the elements of array should be minimum non-negative(as close to zero as possible).
Return the minimum number of elements whose sign needs to be flipped such that the resultant sum is minimum non-negative.
1 <= length of(A) <= 100
Sum of all the elements will not exceed 10,000.
First and only argument is an integer array A.
Return an integer denoting the minimum number of elements whose sign needs to be flipped.
A = [15, 10, 6]
A = [14, 10, 4]
Here, we will flip the sign of 15 and the resultant sum will be 1.
Here, we will flip the sign of 14 and the resultant sum will be 0. Note that flipping the sign of 10 and 4 also gives the resultant sum 0 but flippings there sign are not minimum.
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a question? Checkout Sample Codes for more details.