class Solution {
public:
int maxNonOverlapping(vector<int>& nums, int target) {
unordered_map<int,int> pos;
pos[0]=-1;
int sum=0;
int n=nums.size();
int res=0;
int last=-1;
for(int i=0;i<n;i++){
sum+=nums[i];
if(pos.find(sum-target)!=pos.end() && pos[sum-target]>=last){
res++;
last=i;
}
pos[sum]=i;
}
return res;
}
};