Facebook interview question - Range sum query 2d (immutable)

2295
May 16, 2018
May 23, 2019

Given a large rectangular 2D grid of arbitrarily placed 1's and 0's, write a service that answers the query "how many 1's in a given subgrid?"
Assume that the grid is large, doesn't change and is given to you ahead of time. The query will be called many times so it needs to be fast.

examples:
0001
1010
1110

subgrid marked with *

0001
**10 ---> Output: 3
**10

0001
1**0 ---> Output: 1
1110

Comments (4)