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
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.