Skip to content

Commit b8b1c31

Browse files
committed
Jul 16
1 parent cec7bab commit b8b1c31

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
class Solution:
2+
def maximumLength(self, nums: list[int]) -> int:
3+
n_evens, n_odds = 0, 0
4+
for num in nums:
5+
if num & 1 == 0:
6+
n_evens += 1
7+
else:
8+
n_odds += 1
9+
10+
n_alts, parity = 1, nums[0] & 1
11+
for num in nums[1:]:
12+
if num & 1 != parity:
13+
n_alts += 1
14+
parity = num & 1
15+
return max(n_evens, n_odds, n_alts)
16+
17+
18+
def main():
19+
nums = [1, 2, 3, 4]
20+
assert Solution().maximumLength(nums) == 4
21+
22+
nums = [1, 2, 1, 1, 2, 1, 2]
23+
assert Solution().maximumLength(nums) == 6
24+
25+
nums = [1, 3]
26+
assert Solution().maximumLength(nums) == 2
27+
28+
29+
if __name__ == '__main__':
30+
main()

2025-07-July-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
| July 13 | [2410. Maximum Matching of Players With Trainers](https://leetcode.com/problems/maximum-matching-of-players-with-trainers/) | Medium | Solved |
2020
| July 14 | [1290. Convert Binary Number in a Linked List to Integer](https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer/) | Easy | Solved |
2121
| July 15 | [3136. Valid Word](https://leetcode.com/problems/valid-word/) | Easy | Solved |
22-
| July 16 | []() | | |
22+
| July 16 | [3201. Find the Maximum Length of Valid Subsequence I](https://leetcode.com/problems/find-the-maximum-length-of-valid-subsequence-i/) | Medium | Solved |
2323
| July 17 | []() | | |
2424
| July 18 | []() | | |
2525
| July 19 | []() | | |
@@ -41,5 +41,5 @@
4141
| Level | Problems | Solved | Unsolved |
4242
| --- | --- | --- | --- |
4343
| Easy | 5 | 5 | 0 |
44-
| Medium | 5 | 5 | 0 |
44+
| Medium | 6 | 6 | 0 |
4545
| Hard | 5 | 1 | 4 |

0 commit comments

Comments
 (0)