Today we will see the code to get Prefix sum matrix of a 2D matrix .
- Add the prefix sum of the cell just above and left to it.
- Subtract the prefix sum of the cell on the top-left diagonal cell. We do this because we have added this prefix sum in each of the top and left cell of the given cell. Therefore, we have to subtract it once.
Fig.Getting prefix sum
Code :
Related question for practice :
Comments
Post a Comment