Inclusive Running Sums of an Integer Array

Quick Overview

Inclusive Running Sums of an Integer Array. Return an array whose entry i equals the sum of the original entries nums[0] through nums[i],inclusive.

Inclusive Running Sums of an Integer Array

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem Return an array whose entry i equals the sum of the original entries nums[0] through nums[i],inclusive. ```cpp class Solution { public: vector<int> runningSum(vector<int>& nums); }; ``` ### Examples **Example 1:** ```text Input: nums = [-2,5,-1] Output: [-2,3,2] Explanation: The successive sums are-2,-2+5=3,and3-1=2. ``` **Example 2:** ```text Input: nums = [0,4] Output: [0,4] Explanation: The first prefix is0,and the complete sum is4. ``` ### Constraints - nums has length 1 to 1000. - Each value lies in `[-1000000,1000000]`. ### Contract considerations Output length and position order match the input. ```hint Read the boundary condition Each output includes its own input entry and all preceding entries. Check negative values and a single-entry array. ``` ### Boundary reminders Output length and position order match the input.

Overview: Inclusive Running Sums of an Integer Array. Return an array whose entry i equals the sum of the original entries nums[0] through nums[i],inclusive.

Google logo
Google
Source window: 0–3 months · as of Oct 21, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

Return an array whose entry i equals the sum of the original entries nums[0] through nums[i],inclusive.

class Solution {
public:
    vector<int> runningSum(vector<int>& nums);
};

Examples

Example 1:

Input: nums = [-2,5,-1]
Output: [-2,3,2]
Explanation: The successive sums are-2,-2+5=3,and3-1=2.

Example 2:

Input: nums = [0,4]
Output: [0,4]
Explanation: The first prefix is0,and the complete sum is4.

Constraints

  • nums has length 1 to 1000.
  • Each value lies in [-1000000,1000000] .

Contract considerations

Output length and position order match the input.

Boundary reminders

Output length and position order match the input.