Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Compute the sum of an array recursively

Implement a recursive function to compute the sum of elements in a list.

Python practice6 minRecursion & BacktrackingBeginnerLast updated March 27, 2026

Problem statement

Write a function that takes a list of integers and returns the sum of its elements using recursion. You may not use loops (for/while) or the built-in sum function. Handle the empty list by returning 0.

Task

Reinforce thinking recursively by summing array elements without using loops or built-in sum.

Examples

Simple sum

Input

[1, 2, 3]

Output

6

1 + 2 + 3 = 6

Input format

A list of integers, e.g. [1, 2, 3].

Output format

An integer representing the sum of the list elements.

Constraints

Length of list <= 1000 (recursion depth in Python may be limited; practice uses small inputs).

Samples

Sample 1

Input

[]

Output

0

Empty list sums to 0.