C++ || Easy to Understand || EXPLAINED || PREFIX + MAP
HOPE IT HELPS...\n\nCODE : \n\nclass Solution {\npublic:\n    int numSubmatrixSumTarget(vector<vector<int>>& mat, int target) {\n        int r,c;\n        r = m
HOPE IT HELPS...\n\nCODE : \n```\nclass Solution {\npublic:\n    int numSubmatrixSumTarget(vector<vector<int>>& mat, int target) {\n        int r,c;\n        r = mat.size();\n        c = mat[0].size();\n        int prefix[r+1][c];\n        prefix[r-1][c-1] = mat[r-1][c-1];\n        prefix[r][c-1] = 0;\n        for(int i = c-2 ; i >= 0 ; i--)\n        {\n            prefix[r-1][i] = prefix[r-1][i+1] + mat[r-1][i];\n            prefix[r][i] = 0;\n        }\n        for(int j = r-2 ; j >= 0 ; j--)\n            prefix[j][c-1] = prefix[j+1][c-1] + mat[j][c-1];\n        for(int i = r-2 ; i >= 0 ; i--)\n            for(int j = c-2 ; j >= 0 ;j--)\n                prefix[i][j] = prefix[i+1][j] + prefix[i][j+1] - prefix[i+1][j+1] + mat[i][j];\n      \n        int cnt = 0;\n        for(int i = 0 ; i < r ; i++)\n        {\n            for(int j = i+1; j <= r ; j++)\n            {\n                map<int , int> mp;\n                mp[0] = 1;\n                for(int k = c-1 ; k >= 0 ; k--)\n                {\n                    int sum = prefix[i][k] - prefix[j][k];\n                    int reqSum = sum - target;\n                    cnt += mp[reqSum];\n                    mp[sum]++;\n                }\n            }\n        }\n        return cnt;\n    }\n};\n```\n\nEXPLANATION (By pictures)  : \n![image](https://assets.leetcode.com/users/images/21d220cd-db50-4c51-9fd6-5b8648c51c84_1658128270.3572967.jpeg)\n\n![image](https://assets.leetcode.com/users/images/853219d3-7a98-4747-83db-7bcd862483e7_1658128300.1421673.jpeg)\n\n![image](https://assets.leetcode.com/users/images/981838f9-f919-4724-bc0e-74267d482c7f_1658128331.2134755.jpeg)\n\nCOMPLEXITY : \n\n\n![image](https://assets.leetcode.com/users/images/81f93fd5-cc8e-4954-9a9a-5d771219c759_1658128365.2356606.jpeg)\n\n\n
['Prefix Sum']