Applying for new grad.
You are given a matrix and a sub-matrix. You need to find the number of ones for given sub-matrix
E.g.:
Matrix:
1 0 0 1 1
0 1 0 0 0
1 1 0 0 0
0 0 0 1 0
Sub-matrix:
1 0
0 1
They didn't specify how the sub-matrix would be given as input and asked me to do whatever I feel comfortable. I think the two corner indices of the matrix would make sense. (e.g. [0,0], [1,1])
Find a way to do this in faster than O(M*N) time
Note: Going over the matrix first doesn't count in the time complexity
I wasn't able to arrive at the most efficient solution at that time. I think it has something to do with caching and mapping the sum of every row.
Is ther a Leetcode problem like this?