Largest Element in Array

Practice this coding question on Coding Gurukul.

Problem statement

A mountain expedition stores altitude readings from its route. The final report needs the highest recorded altitude, even if every reading is below the reference level. Your task Find and print the largest integer in the nonempty array. Important details Any position may contain the largest value. Repeated maxima do not require repeated output: print the value once. Negative readings are valid, so initializing a maximum to zero would be incorrect for an entirely negative route. Start with an actual array entry and inspect all remaining values. You need only one scan and constant extra storage; rearranging the readings is unnecessary. Worked example For readings -8, -2, -11, and -2, the highest value is -2. Its two occurrences still produce a single output value.

Input format

The first line contains n. The second line contains n space-separated integers.

Output format

Print the maximum array value.

Constraints

1 <= n <= 100000; -1000000000 <= a[i] <= 1000000000.

Sample input

4
-8 -2 -11 -2

Sample output

-2

Sign in to run or submit a solution in C++, Java or Python.