Milly and special array
Practice
3.7 (176 votes)
Dynamic programming
Approved
Easy Medium
Problem
6% Success 3355 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Milly is playing with an array A of size N. She wants to convert this array into a special array. In the special array, all the negative values appear at the beginning and all the other positive values form the tail of the array. In short, special array will have first negative values and then positive values. Your task is to tell her the minimum number of values that should be changed in the given array to make this one of the special array.

Note:

  • Special array must contain at least one negative and at least one positive value.
  • Special array should not contain 0 as any of it's value.

Input

  • First line of the input will contain T denoting the number of test cases.
  • For every test case, first line will contain N. Next line contains N space separated integers denoting Ai.

Output

  • For every test case, print the required answer in a separate line.

Constraints

  • 1 ≤ T ≤ 10
  • 2 ≤ N ≤ 105
  • 1 ≤ |Ai| ≤ 109
  • Here, || denotes the absolute value.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
375 votes
Tags:
Basic ProgrammingInput/OutputMediumPrefix sumprefix-sum
Points:30
191 votes
Tags:
Binary search algorithmNumber TheoryHiringEasy-MediumReadyOpenApproved
Points:30
191 votes
Tags:
MathematicsEasy-Medium