← Practice problem bank

Dec 30, 2025

Maximum Element Finder

Daily Challenge Archive · Open

mediumarrays

150 pts · 10000 ms · 128 MB · Practice only

Problem

Imagine you are a software engineer working on a new feature for a sports application that needs to display the highest score achieved in a series of games. To accomplish this, you need to find the maximum score from an array of game scores. Your task is to write a program that reads an array of integers from the standard input and outputs the maximum integer value. To solve this, follow these steps: 1. Read the input array of integers. 2. Initialize a variable to store the maximum value found, starting with the first element of the array. 3. Traverse the array, comparing each element to the current maximum value. If an element is greater, update the maximum value. 4. Once all elements have been checked, output the maximum value. Consider edge cases such as arrays with negative numbers, arrays with a single element, and arrays where all elements are the same.

Examples
Given an array [3, 17, 9, 21, 15], the maximum element is 21.
Hints
  • Consider using a simple loop to iterate through the array.
  • Think about how you can keep track of the maximum value as you go through the array.
  • Edge cases to consider include arrays with all negative numbers or arrays with only one number.
  • Optimizing for large arrays might involve minimizing the number of comparisons made, but the simplest solution is often the best for this problem.

Input format

First line: integer n (1 <= n <= 1000), the number of elements. Second line: n space-separated integers.

Output format

Output a single integer: the maximum element.

Constraints

1 <= n <= 1000, -10^9 <= each element <= 10^9

Sample input

5
3 7 2 9 1

Sample output

9

Sign in to submit solutions

Run your code against all test cases and get instant feedback.

Sign in