Oops!! It seems some javascript files did not load. Please hard reload(SHIFT + reload) your page.

Problem Tester: dhruvi

Given an array 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 no. of elements whose sign needs to be flipped such that the resultant sum is minimum non-negative.

**Constraints:**

```
1 <= n <= 100
```

Sum of all the elements will not exceed 10,000.

**Example:**

```
A = [15, 10, 6]
```

ans = 1 (Here, we will flip the sign of 15 and the resultant sum will be 1 )

```
A = [14, 10, 4]
```

ans = 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 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 doubt? Checkout Sample Codes for more details.

Sign Up

to access hints and editorial solutions for**Flip Array**

to access hints and editorial solutions for

Loading...