Java Prefix Sum || Optimised Solution
\nclass Solution {\n    public int[][] rangeAddQueries(int n, int[][] queries) {\n        int [][]mat = new int[n][n];\n        int[][] prefix = new int[n+1][n+
```\nclass Solution {\n    public int[][] rangeAddQueries(int n, int[][] queries) {\n        int [][]mat = new int[n][n];\n        int[][] prefix = new int[n+1][n+1];\n        \n        for(int[] query : queries) {\n            int row1 = query[0], col1 = query[1], row2 = query[2], col2 = query[3];\n            prefix[row1][col1] += 1;\n            prefix[row2 + 1][col2 + 1] += 1;\n            prefix[row1][col2 + 1] -= 1;\n            prefix[row2 + 1][col1] -= 1;\n        }\n        \n        for(int i = 0; i < n; i++) {\n            for(int j = 0; j < n; j++) {\n                prefix[i][j+1] += prefix[i][j];\n            }\n        }\n        \n        for(int i = 0; i < n; i++) {\n            for(int j = 0; j < n; j++) {\n                prefix[i+1][j] += prefix[i][j];\n                mat[i][j] = prefix[i][j];\n            }\n        }\n        return mat;\n    }\n}\n```
['Prefix Sum', 'Java']