Pony2
Coder
Hello,
I'm having trouble troubleshooting a problem with the longest increasing subsequence algorithm. I'm using the code from the blog post, but I'm getting an incorrect output. Here's the code I'm using:
The output I'm getting is 6, when it should be 5
Does anyone have any advice on how I can troubleshoot this?
Thanks in advance!
I'm having trouble troubleshooting a problem with the longest increasing subsequence algorithm. I'm using the code from the blog post, but I'm getting an incorrect output. Here's the code I'm using:
Code:
def lis(arr):
n = len(arr)
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
maximum = 0
for i in range(n):
maximum = max(maximum , lis[i])
return maximum
arr = [10 , 22 , 9 , 33 , 21 , 50 , 41 , 60]
print("Length of lis is", lis(arr))
The output I'm getting is 6, when it should be 5
Does anyone have any advice on how I can troubleshoot this?
Thanks in advance!