Skip to content

Instantly share code, notes, and snippets.

@lovasoa
Last active October 1, 2020 19:58
Show Gist options
  • Save lovasoa/6733017 to your computer and use it in GitHub Desktop.
Save lovasoa/6733017 to your computer and use it in GitHub Desktop.
Solution to the longest increasing subsequence problem, in 5 lines of python
def lis(a):
L = []
for (k,v) in enumerate(a):
L.append(max([L[i] for (i,n) in enumerate(a[:k]) if n<v] or [[]], key=len) + [v])
return max(L, key=len)
inp = [int(a) for a in input("List of integers: ").split(' ')]
print(lis(inp));
@kesav-wanderer
Copy link

wow!!! nice work

@ArthurBook
Copy link

Very useful!!
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment