Largest subarray with 0 sum | Practice | GeeksforGeeks

PHOTO EMBED

Wed May 31 2023 17:07:21 GMT+0000 (Coordinated Universal Time)

Saved by @DxBros #c++ #largest_sub_sum_0 #sde_sheet

    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;
    }
content_copyCOPY

https://practice.geeksforgeeks.org/problems/largest-subarray-with-0-sum/1