Recursion
Recursion-13
Recursion-14
Recursion-15
~/algor $ cat problems/rekursiya-massivdagi-eng-katta-element
Largest element of an array
Easy
1000 ms
64 MB
31%
You are given an array of $n$ integers. Using a recursive function, find the largest (maximum) element of the array.
The recurrence:
$$\max(A, n) = \begin{cases} A[0], & n = 1 \\ \max(A[n - 1], \max(A, n - 1)), & n > 1 \end{cases}$$
Input
The first line contains an integer $n$ ($1 \le n \le 100$). The second line contains $n$ integers $a_i$ separated by spaces ($-10^9 \le a_i \le 10^9$).
Output
The largest element of the array.
Note
$1 \le n \le 100$, $-10^9 \le a_i \le 10^9$
Examples
Input #1
5 3 1 9 4 2
Output #1
9
Input #2
3 -10 -5 -20
Output #2
-5