Easy 0 solved 0% acceptance

Row Sums

Add up every row of a grid.

Problem

Return the sum of each row of the grid, in row order.

Implement row_sums(grid).

Input

grid: A list of rows of integers.

Output

Return one total per row.

Constraints

0 ≤ rows ≤ 1,000; 0 ≤ values per row ≤ 1,000

Examples

Example 1
Input:
grid = [
    [1, 2, 3],
    [4, 5, 6]
]

Expected output:
expected = [6, 15]
Input:
std::vector<std::vector<long long>> grid = {
    {1, 2, 3},
    {4, 5, 6}
};

Expected output:
std::vector<long long> expected = {6, 15};
Input:
long[][] grid = new long[][] {
    new long[] {1, 2, 3},
    new long[] {4, 5, 6}
};

Expected output:
long[] expected = new long[] {6, 15};

Explanation

1+2+3 = 6 and 4+5+6 = 15: [6, 15].

Example 2
Input:
grid = [
    [],
    [7]
]

Expected output:
expected = [0, 7]
Input:
std::vector<std::vector<long long>> grid = {
    {},
    {7}
};

Expected output:
std::vector<long long> expected = {0, 7};
Input:
long[][] grid = new long[][] {
    new long[] {},
    new long[] {7}
};

Expected output:
long[] expected = new long[] {0, 7};

Explanation

An empty row adds up to 0: [0, 7].

References

This challenge is adapted for CodeUtility. Follow the statement and constraints above.

Learn from others

Community solutions

No published solutions yet. Solve this challenge to share the first one.