Skip to content

Instantly share code, notes, and snippets.

@Poorvak
Created January 8, 2019 02:36
Show Gist options
  • Save Poorvak/392ebf55fabbaa5a70c2311f1c2385e5 to your computer and use it in GitHub Desktop.
Save Poorvak/392ebf55fabbaa5a70c2311f1c2385e5 to your computer and use it in GitHub Desktop.
Find the Longest Increasing Subsequence from an array
def populate_incr_subseq_list(arr: list) -> list:
len_of_inp = len(arr)
temp_list = [1] * len_of_inp
for i in range(1, len_of_inp):
for j in range(0, i):
if arr[j] < arr[i]:
temp_list[i] = max(temp_list[1], temp_list[j] + 1)
return temp_list
def find_max_from_list(arr: list) -> int:
lis = 1
for i in arr:
lis = max(lis, i)
return lis
def test_lis():
arr = [3, 4, -1, 0, 6, 2, 3]
assert find_max_from_list(arr=populate_incr_subseq_list(arr=arr)) == 4
assert find_max_from_list(arr=populate_incr_subseq_list(arr=[])) == 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment