CODERE3 - Coder Express 3!!

Mr Durgeshwara was very impressed by Rahul.But now he was in trouble.He has already fixed his daughter's marriage with Thangabali who was the best coder of his town. He got an idea and arranged a contest between Rahul and Thangabali.They have to solve a problem at the same time and whoever solves first will marry Meenamma. Rahul was not such a good coder and was also getting help from Meenamma.Your task is to help Thangabali to solve the problem to create a twist in story .

The problem was that there are large number of builing in the town which are of different heights and all the building are in a single line.
You have to find the maximum possible length of the subsequences of buildings which are possible which are first increasing in heights and then decreasing! Please Note: the heights of the building in the subsequences should be strictly increasing and then strictly decreasing


Input Specification:

First line contains an integer T( 1 < = T < = 100) that represents the number of test cases.Then follows the T containg the integer N(1 < = N < = 1000) specifying the total number of elements and the next line contains the N integers A1,A2,A3...An (1<= Ai< = 1000)

Output Specification:

For each test case, print only one line, the maximum length of such sequence.

Sample input:

1 3 5 6 4 8 4 3 2 1
8 6 3 4 2 1

Sample Output:



for first test case the subsequence is : 1 3 5 6 8 4 3 2 1 for second case it is : 8 6 4 2 1

hide comments
scolar_fuad: 2019-11-20 14:41:34

take lise from forward and from backward
hope its enough to solve this problem
#happy coding

ishancosmos25: 2019-10-29 04:53:02

longest bitonic subsequence :)

amanharitsh: 2019-08-25 06:19:39

Python3 O(N^2) gives TLE :(

harsh_pandey: 2019-07-02 21:18:07

Simple problem for Longest bitonic subsequence.

utkgrover: 2019-05-27 08:15:49

will pass even if done with O(n^2) LIS , but try to go for O(n logn) LIS.

ab_biswas09: 2019-03-18 16:43:29

Very easy problem

zakir068: 2019-02-23 17:23:45

nice problem.just modify the classic lis

sudhanshu6324: 2018-11-14 18:46:08

@mudra03 try 4 4 ans should be 1

castor21: 2018-06-17 07:25:08

AC not working in my house.

harvy98: 2018-05-25 18:58:41

Nice variation of LIS.

Added by:Rajesh Kumar
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:AASF - ABV-IIITM PC-01-9-2013