A high-frequency analytics database at Citadel stores 2D aggregated trade volumes in a prefix-sum matrix of dimension . The matrix was generated from an original raw execution volume matrix according to the 2D prefix sum formula: where and .
Your Task
Implement restore_matrix(b: list[list[int]]) -> list[list[int]] that reconstructs the original matrix from in time using the principle of inclusion-exclusion.
Constraints
Examples
b = [
[2, 5],
[7, 17]
]
# A[0][0] = 2
# A[0][1] = 5 - 2 = 3
# A[1][0] = 7 - 2 = 5
# A[1][1] = 17 - 5 - 7 + 2 = 7
# Output: [[2, 3], [5, 7]]