InterviewBit Academy is now Scaler!
InterviewBit Academy is now Scaler Academy!

Length of Longest Subsequence

Problem Setter: mayank111 Problem Tester: glowing_glare

Given an array of integers, A of length N, find the length of longest subsequence which is first increasing then decreasing.

Input Format:

The first and the only argument contains an integer array, A.

Output Format:

Return an integer representing the answer as described in the problem statement.


1 <= N <= 3000
1 <= A[i] <= 1e7


Input 1:
    A = [1, 2, 1]

Output 1:

Explanation 1:
    [1, 2, 1] is the longest subsequence.

Input 2:
    [1, 11, 2, 10, 4, 5, 2, 1]

Output 2:
Explanation 2:
    [1 2 10 4 2 1] is the longest subsequence.
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Length of Longest Subsequence on Interview Code Editor
Sign Up
to access hints and editorial solutions for Length of Longest Subsequence
Asked In:


Click here to start solving coding interview questions