FunctionRacerProblemsRace

Grid With Row and Column Adds

BeginnerClassesPython, JavaScript, TypeScript, Java, C++

Implement a class GridAdder for a grid of numbers that starts filled with zeros. Rows are numbered from 0 at the top and columns from 0 at the left. Write these methods:

r and c are always inside the grid, and amount may be negative.

The tests call the methods in sequence and compare every return value. The expected list holds null for the constructor and for the methods that return nothing.

Example 1

GridAdder(2, 3)
add_to_row(0, 5)
add_to_col(2, 1)
value_at(0, 2) returns 6
value_at(1, 2) returns 1
value_at(1, 0) returns 0
row_sum(0) returns 16
row_sum(1) returns 1

Row 0 becomes 5 5 5, then column 2 gets 1 more, so row 0 is 5 5 6 (sum 16) and row 1 is 0 0 1 (sum 1).

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Classes problems