I am working on a problem where i would need to find the longest subsequence of integers when removing a maximum of only one value in the original sequence. The output is the length of subsequence.
like INPUT 2 3 4 5 5 6 4 5 then OUTPUT 5 (cause when you could remove a 5, the subsequence would be 2 3 4 5 6)
like INPUT 2 3 4 4 4 5 6 7 then OUTPUT 4 (for this there is no need to remove an integer and the max subsequence is 4 5 6 7)
This is a O(n) implementation which manages your examples correctly, but it shoud be checked on some more cases.