MCPcopy Create free account
hub / github.com/geekcomputers/Python / lis

Function lis

longest_increasing_subsequence_length.py:7–16  ·  view source on GitHub ↗
(a)

Source from the content-addressed store, hash-verified

5
6
7def lis(a):
8 n = len(a)
9 # initialize ans array same lenth as 1
10 ans = [1] * n
11 for i in range(1, n):
12 # now compare with first index to that index
13 for j in range(i):
14 if a[i] > a[j] and ans[i] < ans[j] + 1:
15 ans[i] = ans[j] + 1
16 return max(ans)
17
18
19a = [1, 3, 2, 6, 4]

Calls

no outgoing calls

Tested by

no test coverage detected