Last active
August 23, 2019 10:10
-
-
Save fulippo/c28e96a5c29c01cd54304087e2618bbc to your computer and use it in GitHub Desktop.
Find leaders in array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
numbers = [16, 17, 4, 3, 5, 2] | |
leaders = [] | |
for i, n in enumerate(numbers): | |
remaining = numbers[i+1:] | |
if len(remaining) == 0 or n > max(remaining): | |
leaders.append(n) | |
print(leaders) # [17, 5, 2] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment