Given a 3-Dimensional array of integers A[L][R][C], where L, R, and C are dimensions of the array (Layer, Row, Column). Find prefix sum 3d array for it.
Let Prefix sum 3d array be prefix[L][R][C]. Here prefix[k][i][j] gives sum of all integers between prefix[0][0][0] and prefix[k][i][j] (including both).
Example:
Input:
Output:
Explanation:
Step 0:
Element at (0,0,0) is directly filled.
prefix[0][0][0] = array[0][0][0]
Step 1:
Fill cells of three edges (parallel to x, y, z-axis and made up using cells) using prefix sum on the one-dimensional array.
check this article for 1d prefix sum: prefix sum for 1d array
These edges have common element prefix[0][0][0].
Step 2:
Fill cells of three sides (parallel to xy, yz, zx-plane and made up using cells) using prefix sum on the two-dimensional array.
check this article for 2d prefix sum: prefix sum for 2d array
These sides have common element prefix[0][0][0].
Step 3:
Fill all remaining cells using the general formula.
0 Comments
If you have any doubt let me know.