Count how many positive and negative numbers are in a sorted array, and return the larger count.
You are given a sorted integer array nums in non-decreasing order.
Count:
> 0)< 0)Return the larger of the two counts.
Because the array is sorted, the negatives appear first, then any zeros, then the positives.
nums: a sorted integer array in non-decreasing ordermax(count of positive numbers, count of negative numbers)1 <= nums.length <= 2000-2000 <= nums[i] <= 2000nums is sorted in non-decreasing orderExample 1
Input
nums = [-2,-1,-1,1,2,3]
Output
3
Explanation
There are 3 negative numbers and 3 positive numbers, so the maximum count is 3.
Example 2
Input
nums = [-3,-2,-1,0,0,1,2]
Output
3
Explanation
There are 3 negative numbers and 2 positive numbers, so the answer is 3.
Example 3
Input
nums = [5,20,66,1314]
Output
4
Explanation
All numbers are positive, so the maximum count is 4.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.