categories: computer science
Welcome,
Below you will find a video with a detailed explanation of the algorithm for determining the length of the longest non-decreasing subsequence. Its operation, time complexity, and usefulness. Below you will also find ready-to-use code that you can copy if needed.
Code:
tablica = [1, 7, 2, 1, 8, 9, 4]
dlugosc = [0] * len(tablica)
dlugosc[len(tablica) - 1] = 1
for i in range(len(tablica) - 1, -1, -1):
pom = tablica[i]
for j in range(i + 1, len(tablica), 1):
if tablica[j] > pom:
pom = tablica[j]
dlugosc[i] += 1
for k in dlugosc:
print(str(k) + " ", end="")
Video:
Thank you for reading!
Read more