Practice Subrectangle Queries
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
SubrectangleQueries(rectangle) stores a matrix. updateSubrectangle(row1,col1,row2,col2,newValue) replaces every cell inside the inclusive rectangle. getValue(row,col) returns the current cell. Later overlapping updates override earlier values. Practice approach: Directly assign the affected cells, which is practical for the bounded matrix and call count. Another strategy records updates and scans backward on each query for the newest covering rectangle. Compare update-heavy and query-heavy workloads before selecting one. Test a single-cell update and inclusive bottom-right boundaries.
Source: Subrectangle Queries on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
["SubrectangleQueries","updateSubrectangle","getValue","getValue","updateSubrectangle","getValue"] [[[[1,2],[3,4]]],[0,1,1,1,9],[1,1],[1,0],[1,1,1,1,6],[1,1]]
[null,null,9,3,null,6]
The first update changes the entire second column, leaving (1,0) untouched. The final update changes only (1,1).
Constraints
Related LeetCode Problems
Practice more problems similar to Subrectangle Queries.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.