Given an array having both positive and negative integers. The task is to compute the length of the largest subarray with sum 0.
Example 1:
Input:
N = 8
A[] = {15,-2,2,-8,1,7,10,23}
Output: 5
Explanation: The largest subarray with
sum 0 will be -2 2 -8 1 7.
Your Task:
You just have to complete the function maxLen() which takes two arguments an array A and n, where n is the size of the array A and returns the length of the largest subarray with 0 sum.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(N).
Constraints:
1 <= N <= 10^{5}
-1000 <= A[i] <= 1000, for each valid i

Difficulty: EASY
Tags: String algorithms

Data structures
Skill types: Data structures
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(N).

Starter code:
#Your task is to complete this function

#Your should return the required output

class Solution:

    def maxLen(self, n, arr):

        #Code here

Solutions:
class Solution:

	def maxLen(self, n, arr):
		dic = {}
		sum = 0
		ans = 0
		dic[0] = -1
		for i in range(n):
			sum += arr[i]
			if sum in dic:
				ans = max(ans, i - dic[sum])
			else:
				dic[sum] = i
		return ans


class Solution:

	def maxLen(self, n, arr):
		d = {}
		s = 0
		maxi = 0
		for i in range(n):
			s += arr[i]
			if s == 0:
				maxi = 1 + i
			elif s in d:
				maxi = max(maxi, i - d[s])
			else:
				d[s] = i
		return maxi


class Solution:

	def maxLen(self, n, arr):
		mpp = {}
		maxi = 0
		sum = 0
		for i in range(n):
			sum += arr[i]
			if sum == 0:
				maxi = i + 1
			elif sum in mpp:
				maxi = max(maxi, i - mpp[sum])
			else:
				mpp[sum] = i
		return maxi


class Solution:

	def maxLen(self, n, arr):
		hashmap = {0: -1}
		current_sum = 0
		max_len = 0
		for i in range(n):
			current_sum += arr[i]
			if current_sum in hashmap:
				max_len = max(max_len, i - hashmap[current_sum])
			else:
				hashmap[current_sum] = i
		return max_len


class Solution:

	def maxLen(self, n, arr):
		d = {0: -1}
		p = arr[0]
		d[p] = 0
		ans = 1 if p == 0 else 0
		n = len(arr)
		for i in range(1, n):
			p += arr[i]
			if p in d:
				tmp = i - d[p]
				ans = max(ans, tmp)
			else:
				d[p] = i
		return ans


class Solution:

	def maxLen(self, n, arr):
		hash_map = {}
		max_len = 0
		curr_sum = 0
		for i in range(len(arr)):
			curr_sum += arr[i]
			if arr[i] is 0 and max_len is 0:
				max_len = 1
			if curr_sum is 0:
				max_len = i + 1
			if curr_sum in hash_map:
				max_len = max(max_len, i - hash_map[curr_sum])
			else:
				hash_map[curr_sum] = i
		return max_len


class Solution:

	def maxLen(self, n, arr):
		presum = [0]
		dicti = {}
		maxi = 0
		dicti[0] = 0
		for i in arr:
			presum.append(presum[-1] + i)
			if presum[-1] in dicti:
				temp = len(presum) - 1 - dicti[presum[-1]]
				maxi = max(maxi, temp)
			else:
				dicti[presum[-1]] = len(presum) - 1
		return maxi


class Solution:

	def maxLen(self, n, arr):
		arr = [0] + arr
		n += 1
		sum_arr = [0 for i in range(n)]
		sum_arr[0] = arr[0]
		key_ent = dict()
		key_ent[arr[0]] = 0
		for i in range(1, n):
			sum_arr[i] = sum_arr[i - 1] + arr[i]
			if sum_arr[i] not in key_ent:
				key_ent[sum_arr[i]] = i
		res_len = 0
		for i in range(n):
			res_len = max(res_len, i - key_ent[sum_arr[i]])
		return res_len


class Solution:

	def maxLen(self, n, arr):
		hash_map = {}
		hash_map[0] = -1
		curr_sum = 0
		max_len = 0
		for i in range(n):
			curr_sum += arr[i]
			if curr_sum not in hash_map:
				hash_map[curr_sum] = i
			else:
				max_len = max(max_len, i - hash_map[curr_sum])
		return max_len


class Solution:

	def maxLen(self, n, arr):
		table = {}
		current = 0
		max_len = 0
		for i in range(n):
			current += arr[i]
			if current == 0:
				max_len = i + 1
			if current in table:
				max_len = max(max_len, i - table[current])
			else:
				table[current] = i
		return max_len


class Solution:

	def maxLen(self, n, arr):
		prefix_sum = 0
		max_length = 0
		sum_map = {}
		for i in range(n):
			prefix_sum += arr[i]
			if prefix_sum == 0:
				max_length = i + 1
			if prefix_sum in sum_map:
				length = i - sum_map[prefix_sum]
				max_length = max(max_length, length)
			else:
				sum_map[prefix_sum] = i
		return max_length


class Solution:

	def maxLen(self, n, arr):
		hash_map = {}
		curr_sum = 0
		ans = 0
		hash_map[0] = -1
		for i in range(len(arr)):
			curr_sum += arr[i]
			if curr_sum in hash_map:
				ans = max(ans, i - hash_map[curr_sum])
			else:
				hash_map[curr_sum] = i
		return ans


class Solution:

	def maxLen(self, n, arr):
		ans = 0
		d = {0: -1}
		Sum = 0
		for i in range(n):
			Sum += arr[i]
			if Sum in d:
				ans = max(ans, i - d[Sum])
			else:
				d[Sum] = i
		return ans


class Solution:

	def maxLen(self, n, arr):
		hash = {}
		hash[0] = -1
		curr = 0
		ma = 0
		for i in range(n):
			curr += arr[i]
			if curr not in hash:
				hash[curr] = i
			else:
				ma = max(ma, i - hash[curr])
		return ma


class Solution:

	def maxLen(self, n, arr):
		prefix_sum = 0
		max_length = 0
		sum_map = {}
		for i in range(n):
			prefix_sum += arr[i]
			if prefix_sum == 0:
				max_length = i + 1
			if prefix_sum in sum_map:
				length = i - sum_map[prefix_sum]
				max_length = max(max_length, length)
			else:
				sum_map[prefix_sum] = i
		return max_length
if __name__ == '__main__':
	t = int(input())
	for i in range(t):
		n = int(input())
		arr = list(map(int, input().strip().split()))


class Solution:

	def maxLen(self, n, arr):
		a = 0
		s = 0
		d = {}
		for i in range(n):
			s = s + arr[i]
			if s == 0:
				a = i + 1
				continue
			if s in d:
				if i - d[s] > a:
					a = i - d[s]
			else:
				d[s] = i
		return a


class Solution:

	def maxLen(self, n, arr):
		sum_ = 0
		max_len = 0
		dct = {}
		for i in range(n):
			sum_ += arr[i]
			if sum_ == 0:
				max_len = i + 1
			if sum_ in dct.keys():
				max_len = max(i - dct[sum_], max_len)
			if sum_ not in dct.keys():
				dct[sum_] = i
		return max_len


class Solution:

	def maxLen(self, n, arr):
		dic = {}
		_sum = 0
		_max = 0
		for i in range(n):
			_sum += arr[i]
			if _sum != 0:
				if _sum not in dic:
					dic[_sum] = i
				else:
					_max = max(_max, i - dic[_sum])
			else:
				_max = i + 1
		return _max


class Solution:

	def maxLen(self, n, arr):
		dict = {}
		sum = 0
		maxi = 0
		for i in range(len(arr)):
			sum += arr[i]
			if sum == 0:
				maxi = i + 1
			elif dict.get(sum) == None:
				dict[sum] = i
			else:
				m = i - dict.get(sum)
				maxi = max(maxi, m)
		return maxi


class Solution:

	def maxLen(self, n, arr):
		max_length = 0
		sum_by_index = {}
		current_sum = 0
		for i in range(n):
			current_sum += arr[i]
			if current_sum == 0:
				max_length = i + 1
			if current_sum in sum_by_index:
				max_length = max(max_length, i - sum_by_index[current_sum])
			else:
				sum_by_index[current_sum] = i
		return max_length


class Solution:

	def maxLen(self, n, arr):
		mxlen = 0
		i = -1
		s = 0
		d = {}
		d[s] = i
		while i < n - 1:
			i += 1
			s += arr[i]
			if s not in d:
				d[s] = i
			else:
				size = i - d[s]
				if size > mxlen:
					mxlen = size
		return mxlen


class Solution:

	def maxLen(self, n, arr):
		m = 0
		(i, j) = (0, 0)
		s = 0
		stack = {}
		while j < n:
			s += arr[j]
			if s == 0:
				m = max(m, j - i + 1)
			elif s in stack:
				m = max(m, j - stack[s][0])
			if s in stack:
				stack[s].append(j)
			else:
				stack[s] = [j]
			j += 1
		return m


class Solution:

	def maxLen(self, n, arr):
		d = {}
		sumi = 0
		k = 0
		maxCount = 0
		for i in range(n):
			sumi += arr[i]
			if sumi == k:
				maxCount = max(maxCount, i + 1)
			rem = sumi - k
			if rem in d:
				maxCount = max(maxCount, i - d[rem])
			if sumi not in d:
				d[sumi] = i
		return maxCount


from collections import defaultdict

class Solution:

	def maxLen(self, n, arr):
		h = defaultdict(int)
		subarraysum = 0
		maxlength = 0
		for (i, x) in enumerate(arr):
			subarraysum += x
			if subarraysum == 0:
				maxlength = max(maxlength, i + 1)
			elif subarraysum not in h:
				h[subarraysum] = i
			else:
				maxlength = max(maxlength, i - h[subarraysum])
		return maxlength


class Solution:

	def maxLen(self, n, arr):
		hash_t = {}
		sum = 0
		max_sub = 0
		for i in range(0, n):
			sum += arr[i]
			if sum == 0:
				max_sub = max(max_sub, i + 1)
			if sum not in hash_t:
				hash_t[sum] = [0, i]
			else:
				beg = hash_t[sum][0]
				end = hash_t[sum][1]
				curr_diff = end - beg + 1
				new_diff = i - curr_diff + 1
				if new_diff > max_sub:
					max_sub = new_diff
		return max_sub


class Solution:

	def maxLen(self, n, arr):
		sum_v = dict()
		sum = 0
		large = 0
		for i in range(len(arr)):
			sum = sum + arr[i]
			if sum == 0:
				large = max(large, i + 1)
				continue
			if sum in sum_v:
				large = max(large, i - sum_v[sum])
			else:
				sum_v[sum] = i
		return large


class Solution:

	def maxLen(self, n, arr):
		maxlen = 0
		currsum = 0
		d = {0: -1}
		for i in range(n):
			currsum += arr[i]
			if currsum in d:
				maxlen = max(maxlen, i - d[currsum])
			if currsum == 0:
				maxlen = max(maxlen, i + 1)
			if currsum not in d:
				d[currsum] = i
		return maxlen


class Solution:

	def maxLen(self, n, arr):
		dic = dict()
		s = 0
		res = 0
		dic[0] = -1
		for i in range(n):
			s += arr[i]
			if s not in dic:
				dic[s] = i
			else:
				res = max(i - dic[s], res)
		return res


class Solution:

	def maxLen(self, n, arr):
		hash_map = {}
		val = 0
		count = 0
		for i in range(n):
			val += arr[i]
			if val == 0:
				count = i + 1
			elif val not in hash_map:
				hash_map[val] = i
			else:
				count = max(count, i - hash_map[val])
		return count


class Solution:

	def maxLen(self, n, arr):
		maxi = 0
		g = {}
		sum = 0
		g[0] = -1
		for i in range(n):
			sum = sum + arr[i]
			x = sum
			if x not in g:
				g[x] = i
			else:
				maxi = max(maxi, i - g[x])
		return maxi


class Solution:

	def maxLen(self, n, arr):
		d = dict()
		suma = 0
		maxi = 0
		for i in range(n):
			suma += arr[i]
			if suma == 0:
				maxi = i + 1
				continue
			if suma not in d:
				d[suma] = i
			elif i - d[suma] > maxi:
				maxi = i - d[suma]
		return maxi


class Solution:

	def maxLen(self, n, arr):
		sum_dict = {}
		max_len = 0
		curr_sum = 0
		for i in range(n):
			curr_sum += arr[i]
			if curr_sum == 0:
				max_len = i + 1
			elif curr_sum in sum_dict:
				max_len = max(max_len, i - sum_dict[curr_sum])
			else:
				sum_dict[curr_sum] = i
		return max_len


class Solution:

	def maxLen(self, n, arr):
		mp = {0: -1}
		maxi = 0
		summ = 0
		for i in range(0, n):
			summ = summ + arr[i]
			if summ in mp:
				maxi = max(maxi, i - mp[summ])
			else:
				mp[summ] = i
		return maxi


class Solution:

	def maxLen(self, n, arr):
		d = {}
		d[0] = 1
		sum_ = 0
		max_i = 0
		for i in range(len(arr)):
			sum_ += arr[i]
			if sum_ == 0:
				max_i = i + 1
			elif sum_ in d:
				max_i = max(max_i, i - d[sum_])
			else:
				d[sum_] = i
		return max_i


class Solution:

	def maxLen(self, n, arr):
		sum = 0
		index = 0
		maxx = 0
		dic = dict()
		for i in range(len(arr)):
			sum = sum + arr[i]
			if sum == 0:
				maxx = max(maxx, i + 1)
				continue
			if sum not in dic:
				dic[sum] = i
			else:
				maxx = max(maxx, i - dic[sum])
		return maxx


class Solution:

	def maxLen(self, n, arr):
		sumVal = 0
		maxi = 0
		d = {}
		for (i, v) in enumerate(arr):
			sumVal += v
			if sumVal == 0:
				maxi = i + 1
			elif sumVal in d:
				maxi = max(maxi, i - d[sumVal])
			else:
				d[sumVal] = i
		return maxi


class Solution:

	def maxLen(self, n, arr):
		hash = {}
		total = 0
		max_len = 0
		for i in range(n):
			total += arr[i]
			if total == 0:
				max_len = i + 1
			elif total in hash:
				max_len = max(max_len, i - hash[total])
			if total not in hash:
				hash[total] = i
		return max_len


class Solution:

	def maxLen(self, n, arr):
		m = {}
		sm = 0
		m[0] = -1
		res = 0
		for i in range(n):
			sm += arr[i]
			if m.get(sm) == None:
				m[sm] = i
			else:
				res = max(res, i - m[sm])
		return res


from collections import defaultdict

class Solution:

	def maxLen(self, n, arr):
		prefix = [arr[0]]
		for i in range(1, n):
			prefix.append(prefix[-1] + arr[i])
		if prefix[-1] == 0:
			return n
		mpIndex = defaultdict(list)
		result = 0
		for i in range(len(prefix)):
			if prefix[i] == 0:
				result = max(result, i + 1)
			if mpIndex[prefix[i]] == []:
				mpIndex[prefix[i]] = [i, i]
			else:
				mpIndex[prefix[i]][0] = min(mpIndex[prefix[i]][0], i)
				mpIndex[prefix[i]][1] = max(mpIndex[prefix[i]][1], i)
				result = max(mpIndex[prefix[i]][1] - mpIndex[prefix[i]][0], result)
		return result


class Solution:

	def maxLen(self, n, arr):
		sum_map = {}
		max_length = 0
		curr_sum = 0
		for i in range(n):
			curr_sum += arr[i]
			if arr[i] == 0 and max_length == 0:
				max_length = 1
			if curr_sum == 0:
				max_length = i + 1
			if curr_sum in sum_map:
				max_length = max(max_length, i - sum_map[curr_sum])
			else:
				sum_map[curr_sum] = i
		return max_length


import copy

class Solution:

	def maxLen(self, n, arr):
		d = {}
		count = 0
		s = 0
		for i in range(len(arr)):
			s = s + arr[i]
			if s == 0:
				count = max(i + 1, count)
			if s - 0 in d:
				if i - d[s - 0] > count:
					count = i - d[s - 0]
			if s not in d:
				d[s] = i
		return count


class Solution:

	def maxLen(self, n, arr):
		sums = 0
		maxm = 0
		dict1 = {}
		for i in range(len(arr)):
			sums += arr[i]
			if sums == 0:
				maxm = i + 1
			elif sums not in dict1:
				dict1[sums] = i
			else:
				maxm = max(maxm, i - dict1[sums])
		return maxm


class Solution:

	def maxLen(self, n, arr):
		largest = 0
		maxSum = 0
		seen = {}
		for i in range(n):
			maxSum += arr[i]
			if maxSum == 0:
				largest = i + 1
			elif maxSum in seen:
				largest = max(largest, i - seen[maxSum])
			else:
				seen[maxSum] = i
		return largest


class Solution:

	def maxLen(self, n, nums):
		d = {}
		ans = 0
		summ = 0
		k = 0
		for i in range(n):
			summ += nums[i]
			if summ == k:
				ans = max(ans, i + 1)
			if summ - k in d:
				ans = max(ans, i - d[summ - k])
			else:
				d[summ] = i
		return ans


class Solution:

	def maxLen(self, n, arr):
		maxLen = 0
		k = 0
		pSum = 0
		dic = dict()
		for i in range(n):
			pSum += arr[i]
			if pSum == k:
				maxLen = i + 1
			elif pSum - k in dic:
				length = i - dic[pSum - k]
				maxLen = max(maxLen, length)
			else:
				dic[pSum] = i
		return maxLen


class Solution:

	def maxLen(self, n, arr):
		maxlen = 0
		prefixsum = 0
		freq = {0: -1}
		for i in range(n):
			prefixsum += arr[i]
			if prefixsum in freq:
				maxlen = max(maxlen, i - freq[prefixsum])
			else:
				freq[prefixsum] = i
		return maxlen


class Solution:

	def maxLen(self, n, arr):
		sums = {}
		max_len = 0
		curr_sum = 0
		end_index = -1
		for i in range(n):
			curr_sum += arr[i]
			if arr[i] == 0 and max_len == 0:
				max_len = 1
				end_index = i
			if curr_sum == 0:
				max_len = i + 1
				end_index = i
			if curr_sum in sums:
				if max_len < i - sums[curr_sum]:
					max_len = i - sums[curr_sum]
					end_index = i
			else:
				sums[curr_sum] = i
		return max_len


class Solution:

	def maxLen(self, n, lst):
		curr_sum = 0
		max_l = 0
		d = {}
		for i in range(0, len(lst)):
			curr_sum = curr_sum + lst[i]
			if curr_sum == 0:
				max_l = i + 1
			elif curr_sum in d.keys():
				max_l = max(max_l, i - d[curr_sum])
			else:
				d[curr_sum] = i
		return max_l


class Solution:

	def maxLen(self, n, arr):
		l = {}
		d = 0
		sum = 0
		for i in range(n):
			sum += arr[i]
			if sum == 0:
				d = i + 1
			if sum in l:
				d = max(d, i - l[sum])
			else:
				l[sum] = i
		return d


class Solution:

	def maxLen(self, n, arr):
		tempMap = {}
		maxLenght = 0
		arraySum = 0
		for i in range(n):
			arraySum += arr[i]
			if arraySum == 0:
				maxLenght = max(maxLenght, i + 1)
			elif arraySum not in tempMap.keys():
				tempMap[arraySum] = i
			else:
				maxLenght = max(maxLenght, i - tempMap[arraySum])
		return maxLenght


class Solution:

	def maxLen(self, n, arr):
		sum_map = {0: -1}
		curr_sum = max_len = 0
		for i in range(n):
			curr_sum += arr[i]
			max_len = max(max_len, i - sum_map.get(curr_sum, i))
			sum_map[curr_sum] = sum_map.get(curr_sum, i)
		return max_len


class Solution:

	def maxLen(self, n, arr):
		d = {}
		d[0] = -1
		s = 0
		max_len = 0
		for i in range(n):
			s += arr[i]
			if s not in d:
				d[s] = i
			else:
				max_len = max(max_len, i - d[s])
		return max_len


class Solution:

	def maxLen(self, n, arr):
		(ans, add) = (0, 0)
		seen = {0: -1}
		for i in range(n):
			add += arr[i]
			if add in seen:
				ans = max(ans, i - seen[add])
			else:
				seen[add] = i
		return ans


class Solution:

	def maxLen(self, n, arr):
		hashmap = {}
		longest_subarray_count = 0
		curr_sum = 0
		for (i, each) in enumerate(arr):
			curr_sum += each
			if each == 0 and longest_subarray_count == 0:
				longest_subarray_count = 1
			if curr_sum == 0:
				longest_subarray_count = i + 1
			if curr_sum in hashmap:
				longest_subarray_count = max(longest_subarray_count, i - hashmap[curr_sum])
			else:
				hashmap[curr_sum] = i
		return longest_subarray_count


class Solution:

	def maxLen(self, n, arr):
		maxx = summ = 0
		mpp = {}
		for i in range(n):
			summ += arr[i]
			if summ == 0:
				maxx = i + 1
			elif summ in mpp:
				maxx = max(maxx, i - mpp[summ])
			else:
				mpp[summ] = i
		return maxx


class Solution:

	def maxLen(self, n, arr):
		sumMap = {0: -1}
		maxLen = 0
		currSum = 0
		for i in range(n):
			currSum += arr[i]
			if currSum in sumMap:
				subarrayLen = i - sumMap[currSum]
				maxLen = max(maxLen, subarrayLen)
			else:
				sumMap[currSum] = i
		return maxLen


class Solution:

	def maxLen(self, n, arr):
		hashmap = {}
		curr_sum = 0
		length = 0
		for i in range(n):
			curr_sum += arr[i]
			if curr_sum == 0:
				length = max(length, i + 1)
			if curr_sum in hashmap:
				hashmap[curr_sum].append(i)
			else:
				hashmap[curr_sum] = [i]
		for j in hashmap:
			k = hashmap[j]
			length = max(length, k[-1] - k[0])
		return length


class Solution:

	def maxLen(self, n, arr):
		pref_sum = {0: -1}
		(maxlen, curr_sum) = (0, 0)
		for i in range(len(arr)):
			curr_sum += arr[i]
			if curr_sum in pref_sum:
				maxlen = max(maxlen, i - pref_sum[curr_sum])
			else:
				pref_sum[curr_sum] = i
		return maxlen


class Solution:

	def maxLen(self, n, arr):
		hm = {}
		cur_sum = 0
		max_len = 0
		for (i, j) in enumerate(arr):
			cur_sum += j
			if cur_sum == 0:
				max_len = i + 1
			if cur_sum in hm:
				max_len = max(max_len, i - hm[cur_sum])
			else:
				hm[cur_sum] = i
		return max_len


class Solution:

	def maxLen(self, n, arr):
		sum_indices = {}
		running_sum = 0
		max_length = 0
		for i in range(len(arr)):
			running_sum += arr[i]
			if running_sum == 0:
				max_length = i + 1
			if running_sum in sum_indices:
				max_length = max(max_length, i - sum_indices[running_sum])
			else:
				sum_indices[running_sum] = i
		return max_length


class Solution:

	def maxLen(self, n, arr):
		prefix_sum = {0: -1}
		curr_sum = 0
		max_len = 0
		for i in range(len(arr)):
			curr_sum += arr[i]
			if curr_sum in prefix_sum:
				max_len = max(max_len, i - prefix_sum[curr_sum])
			else:
				prefix_sum[curr_sum] = i
		return max_len


class Solution:

	def maxLen(self, n, arr):
		H = {}
		s = 0
		m = 0
		for i in range(n):
			s += arr[i]
			if s == 0:
				m = i + 1
			if s in H:
				m = max(m, i - H[s])
			else:
				H[s] = i
		return m


class Solution:

	def maxLen(self, n, arr):
		pref = []
		sm = 0
		for num in arr:
			sm += num
			pref.append(sm)
		mp = dict()
		for (i, num) in enumerate(pref):
			if num not in mp:
				mp[num] = [i, i]
			else:
				mp[num][1] = i
		ans = 0
		for num in mp:
			ans = max(ans, mp[num][1] - mp[num][0])
		if 0 in mp:
			ans = max(ans, mp[0][1] + 1)
		return ans


class Solution:

	def maxLen(self, n, arr):
		hashmap = {}
		arrsum = 0
		maxlength = 0
		for i in range(0, len(arr)):
			arrsum += arr[i]
			if arrsum == 0:
				maxlength = i + 1
			if arrsum in hashmap:
				maxlength = max(i - hashmap[arrsum], maxlength)
			else:
				hashmap[arrsum] = i
		return maxlength


class Solution:

	def maxLen(self, n, arr):
		sum = 0
		max_len = 0
		hash_table = {}
		for i in range(len(arr)):
			sum += arr[i]
			if arr[i] == 0 and max_len == 0:
				max_len = 1
			if sum == 0:
				max_len = i + 1
			if sum in hash_table:
				max_len = max(max_len, i - hash_table[sum])
			else:
				hash_table[sum] = i
		return max_len


class Solution:

	def maxLen(self, n, arr):
		m = {}
		max_len = 0
		cur_sum = 0
		for i in range(len(arr)):
			cur_sum += arr[i]
			if arr[i] is 0 and max_len is 0:
				max_len = 1
			if cur_sum is 0:
				max_len = i + 1
			if cur_sum in m:
				max_len = max(max_len, i - m[cur_sum])
			else:
				m[cur_sum] = i
		return max_len


class Solution:

	def maxLen(self, n, arr):
		m = {}
		maxm = 0
		total = 0
		for i in range(len(arr)):
			total += arr[i]
			if total == 0:
				maxm = i + 1
			elif total in m:
				maxm = max(maxm, i - m[total])
			else:
				m[total] = i
		return maxm