Recursive array maximum EASY Tablouri matrici (BAC) Recursivitate (BAC) 10 XP 0 solved
Mobile coding works. A laptop is faster for long sessions.

Problem

A natural number `n` is read, followed by `n` integers representing the elements of an array `v` (indexed from 0 to n-1). Print the maximum value in the array, computed using **a recursive function**. Define a recursive function `maxRec(v, n)` that returns the maximum of the first `n` elements of `v`: ``` maxRec(v, 1) = v[0] maxRec(v, n) = max(v[n-1], maxRec(v, n-1)), for n > 1 ```

Input format

Input input.txt

The first line of input contains the natural number `n`. The second line contains the `n` elements, separated by spaces. - `1 <= n <= 50` - Array elements are integers with absolute value at most `1.000.000`. - The solution must use recursion.

Output format

Output output.txt

The program prints a single integer: the maximum value in the array, followed by a newline.

Example

input
5

3 1 4 1 5
output
5

Ready to solve this challenge?

Create a free account to write code, submit solutions, and track your progress.

⌨️ Keyboard Shortcuts

Code Editor
Run Code
Ctrl Enter
Submit Code
Ctrl Shift Enter
Format Code
Shift Alt F
Toggle Comment
Ctrl /
Undo
Ctrl Z
Redo
Ctrl Y
Navigation
Global Search
/
Show Shortcuts
?
Close Modal
Esc

🔍 Interactive Debugger

0 / 0

Analyzing your code...

📦 Variables

No variables yet

📚 Call Stack
main() line 1
📤 Output
We use cookies

Essential cookies are always active. You can choose to enable preference and analytics cookies. Learn more