✅✅Faster || Easy To Understand || C++ Code
Using Prefix && Hashmap\n\n Time Complexity :- O(N * N * M)\n\n Sapce Complexity :- O(N)\n\n\nclass Solution {\npublic:\n    \n    // this function is for findi
* ***Using Prefix && Hashmap***\n\n* ***Time Complexity :- O(N * N * M)***\n\n* ***Sapce Complexity :- O(N)***\n\n```\nclass Solution {\npublic:\n    \n    // this function is for finding the no. of subarray which has sum equal to target\n    \n    int find(vector<int>& arr, int target)\n    {\n        int n = arr.size();\n        \n        int count = 0;\n        \n        unordered_map<int, int> mp;\n        \n        mp[0] = 1;\n        \n        int curr_sum = 0;\n        \n        for(int i = 0; i < n; i++)\n        {\n            curr_sum += arr[i];\n            \n            int need = curr_sum - target;\n            \n            if(mp.count(need))\n            {\n                count += mp[need];\n            }\n            \n            mp[curr_sum]++;\n        }\n        \n        return count;\n    }\n    \n    \n    int numSubmatrixSumTarget(vector<vector<int>>& matrix, int target) {\n        \n        int n = matrix.size();\n        \n        int m = matrix[0].size();\n        \n        int count = 0;\n        \n        for(int i = 0; i < n; i++)\n        {\n            // arr will store the prefix sum between row [i, k]\n            \n            vector<int> arr(m, 0);\n            \n            for(int k = i; k < n; k++)\n            {\n                for(int j = 0; j < m; j++)\n                {\n                    arr[j] += matrix[k][j];\n                }\n                \n                // call find function\n                \n                count += find(arr, target);\n            }\n        }\n        \n        return count;\n    }\n};\n```\n\n
['C', 'Prefix Sum', 'C++']