[Solved] Find a sequence in another sequence [closed]


A pair of lines associated with two number can only cross if those numbers appear in opposite orders in a and b. Since you state that the first list – a – is sorted (in increasing order) we will only have lines crossing if we pick numbers that are in de-creasing order in b.

You state in the comments that you want to pick the maximum number of elements that fulfil the criteria. (I’m a bit confused, as in your example, you select “5 7”, but you also point out longer sequences that also meet the criteria. I’m going to assume that you do in fact require a longest sequence, such as “3 4 7”.) So you need to find the maximum increasing subsequence of b. This is a well-studied problem: http://en.wikipedia.org/wiki/Longest_increasing_subsequence#Efficient_algorithms

1

solved Find a sequence in another sequence [closed]