Skip to content

Instantly share code, notes, and snippets.

@Ifihan
Created March 12, 2025 21:27
Show Gist options
  • Save Ifihan/18f4cae4d2fe76e1cffdc8760aa1fc3c to your computer and use it in GitHub Desktop.
Save Ifihan/18f4cae4d2fe76e1cffdc8760aa1fc3c to your computer and use it in GitHub Desktop.
Maximum Count of Positive Integer and Negative Integer

Question

Approach

In my approach, I iterate through the list and count the number of positive and negative numbers separately. If a number is greater than zero, I increase the positive count. If a number is less than zero, I increase the negative count. Finally, I return the maximum count between positive and negative numbers.

Implementation

class Solution:
    def maximumCount(self, nums: List[int]) -> int:
        p = 0
        n = 0
        for i in nums:
            if i > 0:
                p += 1
            elif i < 0:
                n += 1
        return max(p,n)

Complexities

  • Time: O(n)
  • Space: O(1)
image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment