c++ - Longest sub-sequence the elements of which make up a set of increasing integers -


find length of longest continuous sub-sequence of array elements of make set of continuous increasing integers. input file consists of number n(the number of elements in array) followed n integers.
example input - 10 1 6 4 5 2 3 8 10 7 7
example output - 6(1 6 4 5 2 3 since make set 1 2 3 4 5 6).
able write algorithm satisfies 0<n<5000 in order 100 points algorithm had work 0<=n<=50000.

how this? arrange array elements in descending order, each coupled index-range local maximum (for example, a[0] = 10 maximum array indexes, [0, 10], while a[3] = 4 local maximum array indexes, [3,3]. traverse list , find longest, continuously descending sequence index-ranges contained in starting range.

10 1 6 4 5 2 3 8 10 7 7 => 10, [ 0,10]     8, [ 1, 7]     7, [ 9,10]     6, [ 1, 6] <--     5, [ 3, 6]    | ranges     4, [ 3, 3]    |     3, [ 5, 6]    | contained     2, [ 5, 5]    | in [1,6]     1, [ 1, 1] <-- 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -