Skip to main content

Longest Increasing Subsequence (LIS)

Definition​

The Longest Increasing Subsequence (LIS) algorithm is a dynamic programming approach used to find the longest subsequence in an array where the elements are in increasing order

Practice​

lis(arr):
# Initialize an array dp to store lengths of longest increasing subsequences
dp = array of length equal to size of arr, initialized with 1s
for i from 0 to length of arr - 1:
for j from 0 to i - 1:
if arr[j] < arr[i]:
# Update the length of longest increasing subsequence ending at index i
dp[i] = max(dp[i], dp[j] + 1)
# Find the maximum value in dp
max_length = maximum value in dp
return max_length