Sum of Array Using Recursion
EasyP3Coding
Return the sum of the elements of arr using recursion. The sum of an empty array is 0.
Example 1
- Input
- arr = [1,2,3,4]
- Output
- 10
Example 2
- Input
- arr = []
- Output
- 0
Example 3
- Input
- arr = [5]
- Output
- 5
Constraints
- 0 <= arr.length <= 500
- -10^6 <= arr[i] <= 10^6
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 8. ⌘Enter runs, ⌘⇧Enter submits.