[Solution] Non-Negative Product CodeChef Solution
Problem
Alice has an array of integers — . She wants the product of all the elements of the array to be a non-negative integer. That is, it can be either or positive. But she doesn't want it to be negative.
To do this, she is willing to remove some elements of the array. Determine the minimum number of elements that she will have to remove to make the product of the array's elements non-negative.
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- The first line of each test case contains a single integer — the number of elements in the array originally.
- The next line contains space-separated integers — , which are the original array elements.
Output Format
For each test case, output on a new line the minimum number of elements that she has to remove from the array.
Explanation:
Test case : The product of the elements of the array is , which is already non-negative. Hence no element needs to be removed, and so the answer is .
Test case : The product of the elements of the array is , which is negative. Alice can remove the element , and the product then becomes non-negative. Hence the answer is .
Test case : The product of the elements of the array is , which is already non-negative. Hence no element needs to be removed, and so the answer is .
Test case : The product of the elements of the array is , which is already non-negative. Hence no element needs to be removed, and so the answer is .
No comments:
Post a Comment