Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Largest Number in a List Compared to All Elements on the right.
###
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