Search
⌘K

Leetcode 304. Range Sum Query 2D - Immutable

Given an immutable m×n matrix, design a data structure to return the sum of any sub-rectangle [row1..row2]×[col1..col2] in O(1) time; the core challenge is to preprocess the matrix (O(mn) space/time) with 2D cumulative/prefix sums to enable constant-time rectangle-sum queries.


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Your account is free and you can post anonymously if you choose.