I have a little complicated problem.
I have this array [34,33,5,78,50,76,82,95,119,31,49,76] and I need to find all the longest increasing and decreasing subsequences. For example, the longest decreasing subsequence you can find has a lenght of three. Then, I need to find all the subsequence with that lenght, e.g: [78,76,76] or [78,50,31] or [34,33,31] etc..
I've been trying to create an algorithm in python that, given an array in input, it returns all the longest decreasing and increasing subsequences, for a while but I couldn't succeed. I've written this so far,
def find_decreasing(seq):
found=[]
for v in seq[:-1]:
for iv in found[:]:
if v > iv[0]:
found.append([v+1]+iv)
found.append([v])
return found
But it doesn't work May you help me?
Thanks for your attention.