Facebook interview question - Range sum query 2d (immutable)
Difficulty: EASYCategory: InterviewExperienceFrequency: 1Asked On 2018-05-16Added By Anonymous
Source: Link
Company: Meta (Facebook)
Role: e3 / e4
Interview Stage: unknown
Location: unknown
Year: unknown
Original Post Content:
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