I am trying to implement the Longest Increasing Subsequence in Python by refering the video here.
I think I have done it correct. A Dry Run of the code also looks fine to me. But the output is incorrect.
d = [3, 2, 6, 4, 5, 1]
l = []
l.append([d[0]])
for i in range(1, len(d)):
l.append([])
for j in range(0, i):
if d[j] < d[i] and len(l[i]) < len(l[j]) + 1:
l[i] = l[j]
l[i].append(d[i])
print(l)
Expected Output: [[3], [2], [2, 6], [2, 4], [2, 4, 5], [1]]
Actual Output: [[3], [2, 6, 4, 5], [2, 6, 4, 5], [2, 6, 4, 5], [2, 6, 4, 5], [1]]
Any Help Would Be Appreciated!
[3, 6],[3, 4],[3, 5],[3, 4, 5],[2, 5]and[4, 5]not in your expected output?