Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Maximum Count of Positive Integer and Negative Integer

Easy

Topics
ArrayBinary SearchCounting

Given a sorted array nums in non-decreasing order, return the maximum between the number of strictly positive integers and the number of strictly negative integers. Zeros count toward neither. Aim for O(log n).

Example 1

Input:  nums = [-2,-1,-1,1,2,3]
Output: 3

Example 2

Input:  nums = [-3,-2,-1]
Output: 3

Example 3

Input:  nums = [5,20,66,1314]
Output: 4

Constraints

  • 1 <= nums.length <= 2000
  • -2000 <= nums[i] <= 2000
  • nums is sorted in non-decreasing order.
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access