Skip to content

Commit d49fc1b

Browse files
committed
Jul 17
1 parent b8b1c31 commit d49fc1b

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution:
2+
def maximumLength(self, nums: list[int], k: int) -> int:
3+
dp = [[0] * k for _ in range(k)]
4+
result = 0
5+
for num in nums:
6+
num %= k
7+
for prev in range(k):
8+
dp[prev][num] = dp[num][prev] + 1
9+
result = max(result, dp[prev][num])
10+
return result
11+
12+
13+
def main():
14+
nums = [1, 2, 3, 4, 5]
15+
k = 2
16+
assert Solution().maximumLength(nums, k) == 5
17+
18+
nums = [1, 4, 2, 3, 1, 4]
19+
k = 3
20+
assert Solution().maximumLength(nums, k) == 4
21+
22+
23+
if __name__ == '__main__':
24+
main()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
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 |
2222
| 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 |
23-
| July 17 | []() | | |
23+
| July 17 | [3202. Find the Maximum Length of Valid Subsequence II](https://leetcode.com/problems/find-the-maximum-length-of-valid-subsequence-ii/) | Medium | Unsolved |
2424
| July 18 | []() | | |
2525
| July 19 | []() | | |
2626
| July 20 | []() | | |
@@ -41,5 +41,5 @@
4141
| Level | Problems | Solved | Unsolved |
4242
| --- | --- | --- | --- |
4343
| Easy | 5 | 5 | 0 |
44-
| Medium | 6 | 6 | 0 |
44+
| Medium | 7 | 6 | 1 |
4545
| Hard | 5 | 1 | 4 |

0 commit comments

Comments
 (0)