Subrectangle Queries
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Implement SubrectangleQueries(rectangle), which wraps a rows x cols integer matrix and supports:
- updateSubrectangle(row1, col1, row2, col2, newValue) sets every cell in the sub-rectangle with top-left corner (row1, col1) and bottom-right corner (row2, col2) (both inclusive) to newValue.
- getValue(row, col) returns the current value at (row, col).
Later updates overwrite earlier ones wherever they overlap. Coordinates always satisfy row1 <= row2 and col1 <= col2 and lie inside the matrix.
Examples
Constraints
- 1 <= rows, cols <= 100
- 1 <= rectangle[i][j], newValue <= 10^9
- 0 <= row1 <= row2 < rows, 0 <= col1 <= col2 < cols
- At most 500 calls in total
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.