int maxLen(vector<int>&A, int n)
{
// Your code here
unordered_map<long long ,int> uMap;
uMap.insert({0, 1});
int ans = 0 ;
long long currSum = 0;
for(int i = 0 ; i < n ; i++){
currSum += A[i];
if(uMap[currSum] > 0)
ans = max(ans, i - uMap[currSum] + 2);
else
uMap[currSum] = i + 2;
}
return ans;
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter