03. 2D Difference Array
โ GFG solution to the 2D Difference Array problem: efficiently apply multiple range updates on 2D matrix using difference array technique with 2D prefix sum optimization. ๐
๐งฉ Problem Description
๐ Examples
Example 1
Input: mat[][] = [[1, 2, 3], opr[][] = [[2, 0, 0, 1, 1], [-1, 1, 0, 2, 2]]
[1, 1, 0],
[4,-2, 2]]
Output: [[3, 4, 3],
[2, 2, -1],
[3, -3, 1]]
Explanation:
- First operation: Add 2 to submatrix from (0,0) to (1,1)
- Second operation: Add -1 to submatrix from (1,0) to (2,2)๐ Constraints
โ
My Approach
2D Difference Array + 2D Prefix Sum
๐ Time and Auxiliary Space Complexity
๐งโ๐ป Code (C++)
โ Code (Java)
๐ Code (Python)
๐ง Contribution and Support
๐Visitor Count
Last updated