• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
July 21, 2022 |6.7K Views
Submatrix Sum Queries
  Share   Like
Description
Discussion

Given a matrix of size M x N, there are large number of queries to find submatrix sums. Inputs to queries are left top and right bottom indexes of submatrix whose sum is to find out. 
How to preprocess the matrix so that submatrix sum queries can be performed in O(1) time.
Example : 
 

tli :  Row number of top left of query submatrix
tlj :  Column number of top left of query submatrix
rbi :  Row number of bottom right of query submatrix
rbj :  Column number of bottom right of query submatrix

 

Submatrix Sum Queries : https://www.geeksforgeeks.org/submatrix-sum-queries/

Read More