BubbleNiceSS
Given an array a of n integers, find the longest nice subsequence of consecutive elements.
The subsequence a[i],…,a[j], i<j, is nice if
(i) a[i]≤a[j]
(ii) a[i]≤a[k]≤a[j], for all k∈[i,j].
InputFirst line contains one positive integer n (2≤n≤1,000,000), where n is the number of elements in the given array. Each of the next n lines contains one integer which represents an element of the array. Elements are in range [0,2 * 10^9].
OutputThe output consists of one integer number: “-1” (without quotes) if nice subsequence doesn’t exist; Otherwise, output the length of the longest nice subsequence.
Input:
6
1
3
4
2
5
0
Output:
5
Submit solution
Coming laterThe grading service will be connected in a later migration step. You can inspect the task and your previous results now.