One common type of follow-up question that is asked during interviews is extending the question in a distributed way. For example, one example could be "how would you solve the problem if the inputs do not fit into memory?".
Given a 2D matrix M X N, support two operations:
Query(row1, col1, row2, col2) such that I get the sum of all numbers in the rectangle ((row1, col1), (row1, col2), (row2, col1), (row2, col2)) and
Update(row, col) to a new number
And query is a very frequent operation and update is a rare operation, so query should be really fast, but update can be slower.
Follow up: How would you solve this in a distributed fashionHow can one prepare for these types of questions? What are some good resources that can help prepare for these questions?