With some comment fyi.

```
class Solution {
public:
int maxSubArrayLen(vector<int>& nums, int k) {
//key accumulate sum from 0 to index
//value will be the index
std::unordered_map<int, int> accSum2Idx;
//
int acc = 0, maxlen = 0;
for (int i = 0; i < nums.size(); ++i) {
acc += nums[i];
if (acc == k) {
//Since we are finding the maxlen, when this satisfy,
//it's always be the maxlen seen so far
maxlen = i + 1;
}
if (accSum2Idx.find(acc - k) != accSum2Idx.end()) {
//two sum exist: acc - x == k, find whether x in map
//noted that the length of subarray from 2 sum will be
//like [0,5] - [0,3] ==> [4, 5], the length is 5 - 3 == 2
maxlen = std::max(maxlen, i - accSum2Idx[acc - k]);
}
if (accSum2Idx.find(acc) == accSum2Idx.end()) {
//only update if not exist, since you are trying to get
//maxlen of the subarray, the smaller the i is, the larger
//the resulting length.
accSum2Idx[acc] = i;
}
}
return maxlen;
}
};
```