Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution{
- public:
- int maxLen(vector<int>&A, int n)
- {
- // Your code here
- unordered_map<int, int> m;
- int subArraySum = 0;
- int maxLength = 0;
- for (int i = 0; i < n; i++)
- {
- subArraySum = subArraySum + A[i];
- if (subArraySum == 0)
- maxLength = max(maxLength, i + 1);
- else if (m.find(subArraySum) == m.end())
- m[subArraySum] = i;
- else
- maxLength = max(maxLength, i - m[subArraySum]);
- }
- return maxLength;
- }
- };
- https://practice.geeksforgeeks.org/problems/largest-subarray-with-0-sum/
Advertisement
Add Comment
Please, Sign In to add comment