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
Hint 1Approach
Hint 2Approach
Hint 3Pseudocode
Hint 4Full solution