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
deadpool_18: 2017-06-01 13:04:37

easy one!

Last edit: 2017-06-01 13:18:56
omprakash_40: 2017-04-20 09:30:39

easy one . Simple Dynamic Programming problem.
Use LIS problem concept.

vengatesh15: 2017-01-27 12:24:45

did using O(nlogn) algo AC in 1 go

chinmay0906: 2016-10-31 14:16:58

Try it in O(nlogn) to learn something new ;-)

harshgupta007: 2016-08-25 22:02:21

Solved in one go!!!
a big fan of shah rukh khan.he is everywhere

iharsh234: 2016-08-19 14:52:49

nothing new still time limit that bad for python/java.
atleast in such problems keep TL fair for all languages.

avisheksanvas: 2016-08-08 21:07:20

Candid! :)

gaurav_07: 2016-08-07 21:02:36


Purav Shah: 2016-07-28 17:50:02

My 300th!!! :D

madhavgaba: 2016-07-20 18:34:43

AC in one go 0.10.......longest bitonic subsequence;)

Last edit: 2016-07-21 06:05:37

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