Skip to content

Commit 0f4d954

Browse files
authored
Update 3202-find-the-maximum-length-of-valid-subsequence-ii.js
1 parent b89bff4 commit 0f4d954

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

3202-find-the-maximum-length-of-valid-subsequence-ii.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
/**
2+
* @param {number[]} nums
3+
* @param {number} k
4+
* @return {number}
5+
*/
6+
const maximumLength = function(nums, k) {
7+
const n = nums.length;
8+
const dp = Array.from({ length: k + 1 }, () => Array(k + 1).fill(0));
9+
let res = 0
10+
for(const e of nums) {
11+
const cur = e % k;
12+
for(let remain = 0; remain < k; remain++) {
13+
const prev = (k + remain - cur) % k;
14+
dp[cur][remain] = Math.max(dp[cur][remain], dp[prev][remain] + 1)
15+
res = Math.max(res, dp[cur][remain])
16+
}
17+
}
18+
19+
return res
20+
};
21+
22+
// another
23+
24+
125
/**
226
* @param {number[]} nums
327
* @return {number}

0 commit comments

Comments
 (0)