Created
July 28, 2020 19:46
-
-
Save Mupati/b2f6129065d29c8fba50a8616411f676 to your computer and use it in GitHub Desktop.
Largest Number in a List Compared to All Elements on the right.
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
### | |
Write code to count how many integers are strictly larger than all the integers to their right. | |
Exclude the last digit since it doesn't have a number to its right. E.g. for [2,3,1] the answer should | |
be 1 while for [12,4,4,2,2,3] the answer is 2. | |
### | |
def larger_than_right(input_list): | |
count = 0 | |
tracker = [] | |
max_length = len(input_list) - 1 | |
while count < max_length: | |
current_number = input_list[count] | |
if all(t < current_number for t in input_list[count+1:]): | |
tracker.append(current_number) | |
count += 1 | |
return len(tracker) | |
def main(): | |
# Test Examples | |
one = [2,3,1] | |
two = [12,4,4,2,2,3] | |
three = [12, 4, 4, 7, 7, 7, 8, 10, 11, 8, 2, 2, 3, 5, 6, 7, 6, 5] | |
print(larger_than_right(one)) | |
print(larger_than_right(two)) | |
print(larger_than_right(three)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment