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

Length of Longest Subsequence


Problem Setter: mayank111 Problem Tester: glowing_glare

Problem Description

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



Problem Constraints

0 <= N <= 3000

-107 <= A[i] <= 107



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.



Example Input

Input 1:

 A = [1, 2, 1]

Input 2:

 A = [1, 11, 2, 10, 4, 5, 2, 1]


Example Output

Output 1:

 3

Output 2:

 6


Example Explanation

Explanation 1:

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

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:

Discussion


Loading...
Click here to start solving coding interview questions