211. Largest in an Array
Foundation1000 ms256 MBSolved by 0%
Print the largest of n integers.
Recursively: the largest value is the bigger of the first element and the largest of everything after it.
The base case here is different from the summing problem. An empty array has a sum of 0 and does not have a largest element, so stop at one element rather than at none.
Constraints - `1 ≤ n ≤ 100000` - `-1000000 ≤ a[i] ≤ 1000000`
Input
The first line contains an integer n.
The second line contains n integers separated by spaces.
Output
Print one integer, the largest of the n values.
Input5
3 9 2 7 4
Output9
Notehas its largest value in the middle
Input1
42
Output42
Noteis a single element, which is the base case
Hint 1Approach
Hint 2Approach
Hint 3Pseudocode
Hint 4Full solution