47. Largest Element in an Array
Foundation1000 ms256 MBSolved by 0%
You are given an array of n integers. Print the largest value in it.
The array is not sorted, and it may contain negative numbers.
Constraints - `1 ≤ n ≤ 100000` - `-1000000 ≤ a[i] ≤ 1000000`
Input
The first line contains an integer n.
The second line contains n space-separated integers.
Output
Print one integer, the largest value in the array.
Input5
3 9 2 9 4
Output9
Notehas the maximum appearing twice
Input3
-8 -2 -15
Output-2
Notecontains only negative numbers, so a running value starting at zero is wrong
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.
Hint 1Where to start
Hint 2The approachOpen hint 1 first. This one carries on from it.
Hint 3PseudocodeOpen hint 2 first. This one carries on from it.
Hint 4Full solutionOpen hint 3 first. This one carries on from it.