Skip to content

Commit 436edf3

Browse files
authored
Create longest_increasing_subsequence.py
The Longest Increasing Subsequence (LIS) problem is to find the length of the longest subsequence of a given sequence such that all elements of the subsequence are sorted in increasing order. For example, the length of LIS for {10, 22, 9, 33, 21, 50, 41, 60, 80} is 6
1 parent bdde826 commit 436edf3

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""
2+
The Longest Increasing Subsequence (LIS) problem is to find the length of the longest subsequence of a given sequence such that all elements of the subsequence are sorted in increasing order. For example, the length of LIS for {10, 22, 9, 33, 21, 50, 41, 60, 80} is 6
3+
"""
4+
def LIS(arr):
5+
n= len(arr)
6+
lis = [1]*n
7+
8+
for i in range(1, n):
9+
for j in range(0, i):
10+
if arr[i] > arr[j] and lis[i] <= lis[j]:
11+
lis[i] = lis[j] + 1
12+
return max(lis)

0 commit comments

Comments
 (0)