Find the largest number in a list.
Input
The first line contains an integer n, the count of numbers.
The second line contains n integers separated by spaces.
Output
A single integer: the maximum of the n numbers.
Find the largest number in a list.
The first line contains an integer n, the count of numbers.
The second line contains n integers separated by spaces.
A single integer: the maximum of the n numbers.
Example 1
3 4 2 7
7
The largest of 4, 2, 7 is 7.
Example 2
1 5
5
A single element is the maximum.
Example 3
5 -3 -1 -7 -2 -9
-1
With all negatives, the closest to zero wins: -1.
Read all the numbers, then track the largest as you go — or use a built-in max function.
Reading everything at once and splitting on whitespace handles both the count and the numbers uniformly.
Read all integers; the first is the count, the rest are the list. Print the maximum of the list.
import sys
data = sys.stdin.read().split()
n = int(data[0])
nums = list(map(int, data[1:1 + n]))
print(max(nums))
Tell us what needs to change, who it affects and any important deadline. We will review the context and reply with useful next questions.