Skip to content

Commit 0972713

Browse files
committed
Mar 12
1 parent b34dac8 commit 0972713

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
class Solution:
2+
def __binary_search(self, nums: list[int], target: int) -> int:
3+
left, right = 0, len(nums) - 1
4+
position = len(nums)
5+
while left <= right:
6+
mid = (left + right) // 2
7+
if nums[mid] < target:
8+
left = mid + 1
9+
else:
10+
position = mid
11+
right = mid - 1
12+
return position
13+
14+
def maximumCount(self, nums: list[int]) -> int:
15+
negatives = self.__binary_search(nums, 0)
16+
positives = len(nums) - self.__binary_search(nums, 1)
17+
return max(negatives, positives)
18+
19+
20+
def main():
21+
nums = [-2, -1, -1, 1, 2, 3]
22+
assert Solution().maximumCount(nums) == 3
23+
24+
nums = [-3, -2, -1, 0, 0, 1, 2]
25+
assert Solution().maximumCount(nums) == 3
26+
27+
nums = [5, 20, 66, 1314]
28+
assert Solution().maximumCount(nums) == 4
29+
30+
31+
if __name__ == '__main__':
32+
main()

2025-03-March-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
| March 09 | [3208. Alternating Groups II](https://leetcode.com/problems/alternating-groups-ii/) | Medium | Unsolved |
1616
| March 10 | [3306. Count of Substrings Containing Every Vowel and K Consonants II](https://leetcode.com/problems/count-of-substrings-containing-every-vowel-and-k-consonants-ii/) | Medium | Unsolved |
1717
| March 11 | [1358. Number of Substrings Containing All Three Characters](https://leetcode.com/problems/number-of-substrings-containing-all-three-characters/) | Medium | Solved |
18-
| March 12 | []() | | |
18+
| March 12 | [2529. Maximum Count of Positive Integer and Negative Integer](https://leetcode.com/problems/maximum-count-of-positive-integer-and-negative-integer/) | Easy | Solved |
1919
| March 13 | []() | | |
2020
| March 14 | []() | | |
2121
| March 15 | []() | | |
@@ -40,6 +40,6 @@
4040
## Summary
4141
| Level | Problems | Solved | Unsolved |
4242
| --- | --- | --- | --- |
43-
| Easy | 4 | 4 | 0 |
43+
| Easy | 5 | 5 | 0 |
4444
| Medium | 7 | 4 | 3 |
4545
| Hard | 0 | 0 | 0 |

0 commit comments

Comments
 (0)