#124Easy
Array maximum without loops
Time: 1 s · Memory: 256 MB
- Recursion
Statement
You are given an array of numbers. Find the largest element without loops, using recursion.
Input format
The first line contains (). The second line contains integers ().
Output format
A single integer — the largest element of the array.
Examples
Input
5 3 9 -2 9 4
Output
9
Input
3 -5 -1 -7
Output
-1
Note
There are two ways. One by one: , the base case is a single element. In halves: split the array in the middle, find the maximum of each half recursively and take the larger.
In Python the recursion depth is limited to about calls, so for the one-by-one way raises RecursionError. Splitting in halves needs a depth of only (or raise the limit with sys.setrecursionlimit).
