Snippets Collections
    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;
    }
star

Wed May 31 2023 17:07:21 GMT+0000 (Coordinated Universal Time) https://practice.geeksforgeeks.org/problems/largest-subarray-with-0-sum/1

#c++ #largest_sub_sum_0 #sde_sheet

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension