C++ || Easy solution || Detailed explanation
Prerequisite: https://leetcode.com/problems/subarray-sum-equals-k/ (if you don\'t know this question, please first solve it. Otherwise, understanding current pr
**Prerequisite:** https://leetcode.com/problems/subarray-sum-equals-k/ (if you don\'t know this question, please first solve it. Otherwise, understanding current problem is difficult)\n```\nint subarraySum(vector<int>& nums, int k) {\n\tunordered_map<int,int> um;\n\tum[0] = 1;\n\tint curr = 0;\n\tint ans = 0;\n\tfor(auto it: nums){\n\t\tcurr += it;\n\t\tint rem = curr-k;\n\t\tif(um.find(rem) != um.end()){\n\t\t\tans += um[rem];\n\t\t}\n\t\tum[curr] += 1;\n\t}\n\treturn ans;\n}\n```\n\nBack to this problem:\n```\nclass Solution {\npublic:\n    int subarraySum(vector<int> &nums, int k){\n        unordered_map<int,int> um;\n        um[0] = 1;\n        int curr = 0;\n        int ans = 0;\n        for(auto it: nums){    \n            curr += it;\n            int rem = curr-k;\n            if(um.find(rem) != um.end()){\n                ans += um[rem];\n            }\n            um[curr] += 1;\n        }\n        return ans;\n    }\n    \n    int numSubmatrixSumTarget(vector<vector<int>>& matrix, int target) {\n        int ans = 0;\n\t\t// Each iteration calculates the count for submatrix from row i to matrix.size()\n        for(int i=0; i<matrix.size(); i++){\n\t\t\t// Sum stores the sum of the elements from row i to j \n            vector<int> sum(matrix[0].size(), 0);\n            for(int j=i; j<matrix.size(); j++){\n                for(int k=0; k<matrix[0].size(); k++){\n                    sum[k] += matrix[j][k];\n                }\n\t\t\t\t// Now calculate the count for the submatrix from row i to j\n                ans += subarraySum(sum, target);\n            }\n        }\n        \n        return ans;\n    }\n};\n```\n```\ncout << "Upvote the solution if you like it !!" << endl;\n```
['C', 'C++']