Cumulative Total

EasyData EngineeringPrefix SumArray

Description

Given an array nums, return the running cumulative total, where each position holds the sum of all values up to and including it.

Examples

Input:nums = [1,2,3,4]
Output:[1,3,6,10]
Explanation:

Accumulating the values left to right yields [1,3,6,10].

Input:nums = [5]
Output:[5]
Explanation:

Accumulating the values left to right yields [5].

Input:nums = [-1,1,-1,1]
Output:[-1,0,-1,0]
Explanation:

Accumulating the values left to right yields [-1,0,-1,0].

Constraints

  • 1 ≤ nums.length ≤ 10⁴

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.