Skip to content

Instantly share code, notes, and snippets.

@fulippo
Last active August 23, 2019 10:10
Show Gist options
  • Save fulippo/c28e96a5c29c01cd54304087e2618bbc to your computer and use it in GitHub Desktop.
Save fulippo/c28e96a5c29c01cd54304087e2618bbc to your computer and use it in GitHub Desktop.
Find leaders in array
#!/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