Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    3201 - Find the Maximum Length of Valid Subsequence I\.

    Medium

    You are given an integer array nums.

    A subsequence sub of nums with length x is called valid if it satisfies:

    • (sub[0] + sub[1]) % 2 == (sub[1] + sub[2]) % 2 == ... == (sub[x - 2] + sub[x - 1]) % 2.

    Return the length of the longest valid subsequence of nums.

    A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.

    Example 1:

    Input: nums = 1,2,3,4

    Output: 4

    Explanation:

    The longest valid subsequence is [1, 2, 3, 4].

    Example 2:

    Input: nums = 1,2,1,1,2,1,2

    Output: 6

    Explanation:

    The longest valid subsequence is [1, 2, 1, 2, 1, 2].

    Example 3:

    Input: nums = 1,3

    Output: 2

    Explanation:

    The longest valid subsequence is [1, 3].

    Constraints:

    • <code>2 <= nums.length <= 2 * 10<sup>5</sup></code>

    • <code>1 <= numsi<= 10<sup>7</sup></code>

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Integer maximumLength(IntArray nums)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait