categories: computer science
Hello everyone,
Below you will find a video with a detailed explanation of the algorithm for determining the length of the longest contiguous non-decreasing subsequence. Its operation, time complexity, and usefulness. Below you will also find ready-made code to copy if needed.
Code:
tablica = [1, 4, 2, 3, 6, 7, 9, 10]
def podciag(tab):
dlugosc = len(tab)
max = -1000
wskaznik = 0
for i in range(len(tab)):
if wskaznik < i:
wskaznik = i
while wskaznik < dlugosc - 1 and tab[wskaznik] <= tab[wskaznik + 1]:
wskaznik += 1
zmiennaDl = wskaznik - i + 1
if zmiennaDl > max:
max = zmiennaDl
wskaznik = 0
return max
print(podciag(tablica))
Video:
Thank you for reading!
Read more