I wrote a code to obtain non decreasing sub-sequence from a python list
lis = [3, 6, 3, 8, 6, 4, 2, 9, 5]
ind = 0
newlis = []
while ind < len(lis):
minele = min(lis[ind:])
newlis.append(minele)
ind = lis.index(minele) + 1
print(newlis)
Though it seems to be working fine with the testcases I tried, is there a more efficient way to do this, because the worst cast time complexity of this code is O(n^2) for the case the list is already sorted, assuming the built-in min method uses linear search.
To be more precise, I want longest possible non decreasing sub-list and the sub-list should start with the minimum element of the list. And by sub-list, I mean that the elements need not be in a contiguous stretch in the given original list (lis).