In the leader

Given an array of numbers, an element is called a leader if it is greater than all the elements in front of it. What is the sum of the leaders in the text file?

As an explicit example, in the array [ 3 , 14 , 2 , 1 , 7 , 6 , 5 ] [3, 14, 2, 1, 7, 6, 5] , the leaders of the array are 14 and 7.


The answer is 630.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Rushikesh Jogdand
Jul 10, 2016
1
2
3
4
5
6
7
8
9
with open('l.txt','r') as f:
    exec('a=['+f.read()+']')
su=0
ma=a[-1]
for i in range(len(a)-1,-1,-1):
    if a[i]>ma:
        ma=a[i]
        su+=ma
print(su)

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...