Answer to Question #235068 in Python for kaavya

Question #235068

Maximum

You are given N number of inputs. Print the maximum of them after each input.

Input

The first line of input is an integer N. The next N lines each contain an integer as input.

Explanation

In the example, you are given

6 inputs 1, 0, 3, 2, 9, 8.

1 is maximum in the input 1.

1 is maximum in the input 1, 0.

3 is maximum in the input 1, 0, 3.

3 is maximum in the input 1, 0, 3, 2.

9 is maximum in the input 1, 0, 3, 2, 9.

9 is maximum in the input 1, 0, 3, 2, 9, 8.

 


So, the output should be


1

3

3

9

9


Sample Input 1

6

1


3

2

9

8

Sample Output 1

1

1

3

3

9

9

Sample Input 2

5

1

2

3

4

5

Sample Output 2

1

2

3

4

5




1
Expert's answer
2021-09-09T17:09:06-0400
N = int(input())


li = []
for i in range(0,N):
    num = int(input())
    if len(li)==0:
        print(num)
        li.append(num)
    else:
        print(max(li[len(li)-1],num))
        li.append(num)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS