How to find all elements (leaders) in a list that are greater than all elements to their right in Python

1 Answer

0 votes
def PrintArrayLeaders(lst): 
    size = len(lst)
    
    for i in range(0, size): 
        for j in range(i + 1, size): 
            if lst[i] <= lst[j]: 
                break
        if j == size-1: 
            print (lst[i], end=' ') 
  
lst = [1, 99, 16, 5, 75, 9, 50, 60, 0, 19] 

PrintArrayLeaders(lst) 



'''
run:

99 75 60 0 19 

'''

 



answered Aug 30, 2022 by avibootz
...