Maximum Count of Positive Integer and Negative Integer

Since the list is sorted, we can take advantage of this to make our solution more efficient.

Here’s a Python function that achieves this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
class Solution:
    def maximumCount(self, nums: List[int]) -> int:
        neg_count = 0
        pos_count = 0

        # Count the number of negative and positive integers
        for num in nums:
            if num < 0:
                neg_count += 1
            elif num > 0:
                pos_count += 1

        # Return the maximum count
        return max(neg_count, pos_count)

This function first initializes two counters, neg_count and pos_count, to zero. Then it iterates over each number in the given list. If a number is negative, it increments neg_count, and if a number is positive, it increments pos_count. After it has gone through all the numbers, it returns the maximum of neg_count and pos_count.