Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Question: Write a Python program to find the length of the longest increasing subsequence in an array.
Answer:

def longest_increasing_subsequence(arr):

  n = len(arr)\n lis = [1]*n

  for i in range(1, n):

    for j in range(0, i):

      if arr[i] > arr[j] and lis[i] < lis[j] + 1:

        lis[i] = lis[j] + 1

          return max(lis)

Example:

longest_increasing_subsequence([10, 22, 9, 33, 21, 50, 41, 60, 80])  # Output: 6
Is it helpful? Yes No

Most helpful rated by users:

©2025 WithoutBook