Class Solution
-
- All Implemented Interfaces:
public final class Solution3202 - Find the Maximum Length of Valid Subsequence II.
Medium
You are given an integer array
numsand a positive integerk.A subsequence
subofnumswith lengthxis called valid if it satisfies:(sub[0] + sub[1]) % k == (sub[1] + sub[2]) % k == ... == (sub[x - 2] + sub[x - 1]) % k.
Return the length of the longest valid subsequence of
nums.Example 1:
Input: nums = 1,2,3,4,5, k = 2
Output: 5
Explanation:
The longest valid subsequence is
[1, 2, 3, 4, 5].Example 2:
Input: nums = 1,4,2,3,1,4, k = 3
Output: 4
Explanation:
The longest valid subsequence is
[1, 4, 1, 4].Constraints:
<code>2 <= nums.length <= 10<sup>3</sup></code>
<code>1 <= numsi<= 10<sup>7</sup></code>
<code>1 <= k <= 10<sup>3</sup></code>
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final IntegermaximumLength(IntArray nums, Integer k)-
-
Method Detail
-
maximumLength
final Integer maximumLength(IntArray nums, Integer k)
-
-
-
-