Practice
Matrix Row and Column Totals
2023/May/June·Variant 1
MEDIUMArrays
A 3×3 grid of integers is stored in Grid. Output the total of each row (top to bottom), then the total of each column (left to right).
Input: 9 integers, filling the grid row by row. Output: 3 row totals, then 3 column totals — one per line.
Example:
Input: 1
2
3
4
5
6
7
8
9
Output: 6
15
24
12
15
18
Premium is coming soon. All grading features are currently unlocked.
Sample Test Cases
Test 1: Sequential grid
Inputs: 1, 2, 3, 4, 5, 6, 7, 8, 9
Expected: 6
15
24
12
15
18
Test 2: All values equal
Inputs: 2, 2, 2, 2, 2, 2, 2, 2, 2
Expected: 6
6
6
6
6
6