Search⌘ K
AI Features

DIY: Range Sum Query 2D — Immutable

Understand how to solve the 2D range sum query problem by implementing a NumMatrix class in Rust. Learn to calculate the sum of elements within a specified sub-rectangle of a matrix using efficient methods. This lesson guides you through handling multiple queries on a fixed matrix, preparing you for similar coding interview problems.

Problem statement

Given an m * n matrix, you need to handle multiple queries of the following type:

Calculate the sum of the elements of the matrix inside the rectangle defined by its upper left corner, (row1,col1)(row1, col1) ...