Problem · Array

Find Max Length of Subsequence

Learn this problem
EasyGooglePHONE SCREEN
See Google hiring insights

Problem statement

Given a list of integers, the task is to find the maximum length of subsequence having increasing consecutive elements that increase by a value of 1.

Function

findMaxLengthOfSubsequence(nums: int[]) → int

Complete the function findMaxLengthOfSubsequence in the editor.

findMaxLengthOfSubsequence has the following parameter:

  1. int[] nums: an array of integers

Returns

int: the maximum length of the subsequence

Examples

Example 1

nums = [1, 0, 2, 3, 2, 4, 9, 6, 5]return = 5

The longest subsequence with consecutive elements increasing by 1 is 1, 2, 3, 4, 5, which has a length of 5.

Constraints

  • 1 <= nums.length <= 10^5
  • -10^9 <= nums[i] <= 10^9

More Google problems

drafts saved locally
public int findMaxLengthOfSubsequence(int[] nums) {
  // write your code here
}
nums[1, 0, 2, 3, 2, 4, 9, 6, 5]
expected5
checking account