Educatifu
Open menu

Maximum in a List

Easyarrays

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.

Examples

Example 1

Input
3
4 2 7
Output
7

The largest of 4, 2, 7 is 7.

Example 2

Input
1
5
Output
5

A single element is the maximum.

Example 3

Input
5
-3 -1 -7 -2 -9
Output
-1

With all negatives, the closest to zero wins: -1.

Constraints

  • 1 <= n <= 10^5
  • -10^9 <= each number <= 10^9

Hints

Reveal hint 1

Read all the numbers, then track the largest as you go — or use a built-in max function.

Reveal hint 2

Reading everything at once and splitting on whitespace handles both the count and the numbers uniformly.

Reference solution (spoiler — try it yourself first)

Approach

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))

← All practice problems

Bring us the problem, not a perfect specification

Tell us what needs to change, who it affects and any important deadline. We will review the context and reply with useful next questions.

  1. 01Share contextDescribe the workflow, constraint or risk.
  2. 02Clarify togetherWe identify missing facts and useful options.
  3. 03Choose a startAgree a focused assessment or delivery step.
Start a conversation