Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Problem No 8

Compute Running Total

Easy

8 minute session

Summary

Practice accumulating values across a list to produce running totals.

Problem statement

Given a list of integers nums, compute the running total list where the i-th element of the result is the sum of nums[0] through nums[i]. Use loops to iterate the input list and accumulate the sum incrementally.

Task

Given a list of numbers, return a new list where each element is the running total up to that index.

Examples

Basic running total

Input

compute_running_total([1, 2, 3])

Output

[1, 3, 6]

Explanation

The running totals are 1, 1+2=3, 1+2+3=6.

Input format

A single function call compute_running_total(nums) where nums is a list of integers.

Output format

Return a list of integers representing the running totals.

Constraints

0 <= len(nums) <= 10000. Each number fits in Python's integer type.

Samples

Sample input 0

compute_running_total([5, -2, 7])

Sample output 0

[5, 3, 10]

Explanation 0

Running totals: 5, 5+(-2)=3, 3+7=10.

Code editor
Loading editor…

AI assistant

Ask me anything!

Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.

Chat history is temporary and will not be saved.

02:27 AM

Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.