for example:
s = <6, 5, 4, 3, 2, 1>, s1 = <6, 4, 1>, s2 = <5, 2>, s3 = <5, 3, 2>
Given s
as a sequence, s1
and s2
are the valid subsequences to be considered, but s3
is not because it contains a consecutive elements 3 and 2.
How do you find a longest such a subsequence so that it is monotonically decreasing in O(n^2)
I am aware of the version of the question that contains monotonic increase/ decrease.
But the additional condition here makes it difficult.
A trivial solution would be to start at i = n'th
element as well as at j = (n-1)'th
element, solve as if solving for longest monotonically decreasing subsequence with consideration that next element is at (i-2)'th
and (j-2)'th
respectively and compare the length of two at the end. This will still give the O(n^2)
, but does seem way too trivial.
Is there a better approach?