Maximum Count of Positive Integer and Negative Integer
Given an array nums sorted in non-decreasing order, return the larger of two counts: the number of positive integers and the number of negative integers in nums. Zero is neither positive nor negative.
30:00
Maximum Count of Positive Integer and Negative Integer
Given an array nums sorted in non-decreasing order, return the larger of two counts: the number of positive integers and the number of negative integers in nums. Zero is neither positive nor negative.
Example 1:
Input: {"nums":[-2,-1,-1,1,2,3]}
Output: 3
Constraints:
1≤nums.length≤2000
−2000≤nums[i]≤2000
nums is sorted in non-decreasing order.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"nums":[-2,-1,-1,1,2,3]}
nums is sorted, so it splits into three blocks: negatives, zeros, positives. Two binary searches find the two block edges in O(log n).