FastPrepFastPrep
Problem Brief

Find Max Length of Subsequence

PHONE SCREEN
See Google online assessment and hiring insights

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 Description

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

1Example 1

Input
nums = [1, 0, 2, 3, 2, 4, 9, 6, 5]
Output
5
Explanation

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

public int findMaxLengthOfSubsequence(int[] nums) {
  // write your code here
}
Input

nums

[1, 0, 2, 3, 2, 4, 9, 6, 5]

Output

5

Sign in to submit your solution.