Skip to content

2529. Maximum Count of Positive Integer and Negative Integer #1422

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We need to determine the maximum count between positive and negative integers in a given sorted array. The array is sorted in non-decreasing order, which allows us to efficiently find the counts using binary search.

Approach

  1. Binary Search for First Non-Negative Element: We use binary search to find the first index where the element is greater than or equal to zero. This index helps us determine the count of negative numbers, as all elements before this index are negative.
  2. Binary Search for First Positive Element: Similarly, we use binary search to find the first index where the element is strictly positive. This index helps us determine the count of positive numbers, as all elements from…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@topugit
Comment options

topugit Mar 12, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Mar 12, 2025
Maintainer Author

Answer selected by topugit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested easy Difficulty
2 participants