Skip to content
Onsite

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

Run checks the 3 visible tests, Submit all 8.