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:
|
|
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
.