Given an array of integers, how can we generate all the increasing subsequnces of length of 4 ?
Example: given this list
l = [1, 2, 4, 5, 3, 6] The answer should be :
[1, 2, 3, 6] [1, 2, 4, 5] [1, 2, 4, 6] [1, 2, 5, 6] [1, 4, 5, 6] [2, 4, 5, 6] I generated this algorithm using python :
def verif(x,temp): work=[] for k in temp: if len(k)<4 : if k[-1] < x : work.append(k+[x]) return work+[[x]] temp=[[1]] for i in range(1,len(l)): print(i) zeta=verif(l[i],temp) for i in zeta: if len(i)==4 : print(i) temp+=zeta zeta=[] I want to improve my approach , which is very slow for bigger lists unfortunately , is there another algortihm which works faster ?