`{"id":"5af6789e-b602-4548-88e5-5f205f76cb40","name":"Largest Subarray With Zero Sum","description":"1. You are given an array(arr) of integers.\r\n2. You have to find the length of the largest subarray with sum 0.","inputFormat":"A number N\r\narr1\r\narr2.. N numbers","outputFormat":"A number representing the length of largest subarray with zero sum.","constraints":"1 &lt;= N &lt;= 10^6\r\n1 &lt;= arr[i] &lt;= 10^4","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\n\nint solution(vector<int> arr) {\n //write your code here\n}\n\nint main()\n{\n int n;\n cin >> n;\n vector<int>arr(n, 0);\n for (int i = 0; i < n; i++)\n {\n cin >> arr[i];\n };\n\n cout << solution(arr);\n return 0;\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\t\r\n\tpublic static int solution(int[] arr) {\r\n\t\t// write your code here\r\n\r\n\t\treturn 0;\r\n\t}\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint[] arr = new int[scn.nextInt()];\r\n\t\tfor (int i = 0; i < arr.length; i++) {\r\n\t\t\tarr[i] = scn.nextInt();\r\n\t\t}\r\n\t\tSystem.out.println(solution(arr));\r\n\t}\r\n\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"8\r\n15 -2 2 -8 1 7 10 23","sampleOutput":"5\r\n","questionVideo":"https://www.youtube.com/embed/_yGf2rxwZlA?end=21","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"ec6515dc-6811-4c65-912f-0134b65df120","name":"HashMap and Heap For Intermediate","slug":"hashmap-and-heap-for-intermediate-10002","type":0},{"id":"53e0405f-a507-4490-8ab3-2145a762107e","name":"Largest Subarray With Zero Sum","slug":"largest-subarray-with-zero-sum","type":1}],"next":{"id":"0a5bb13e-289a-42bd-b4ba-8159b2109600","name":"Largest Subarray with Zero Sum MCQ","type":0,"slug":"largest-subarray-with-zero-sum-mcq"},"prev":{"id":"faab5f79-85ab-4cad-9231-293156e4296f","name":"Count Distinct Elements In Every Window Of Size K","type":3,"slug":"count-distinct-elements-in-every-window-of-size-k"}}}`

# Largest Subarray With Zero Sum

1. You are given an array(arr) of integers. 2. You have to find the length of the largest subarray with sum 0.

`{"id":"5af6789e-b602-4548-88e5-5f205f76cb40","name":"Largest Subarray With Zero Sum","description":"1. You are given an array(arr) of integers.\r\n2. You have to find the length of the largest subarray with sum 0.","inputFormat":"A number N\r\narr1\r\narr2.. N numbers","outputFormat":"A number representing the length of largest subarray with zero sum.","constraints":"1 &lt;= N &lt;= 10^6\r\n1 &lt;= arr[i] &lt;= 10^4","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\n\nint solution(vector<int> arr) {\n //write your code here\n}\n\nint main()\n{\n int n;\n cin >> n;\n vector<int>arr(n, 0);\n for (int i = 0; i < n; i++)\n {\n cin >> arr[i];\n };\n\n cout << solution(arr);\n return 0;\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\t\r\n\tpublic static int solution(int[] arr) {\r\n\t\t// write your code here\r\n\r\n\t\treturn 0;\r\n\t}\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint[] arr = new int[scn.nextInt()];\r\n\t\tfor (int i = 0; i < arr.length; i++) {\r\n\t\t\tarr[i] = scn.nextInt();\r\n\t\t}\r\n\t\tSystem.out.println(solution(arr));\r\n\t}\r\n\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"8\r\n15 -2 2 -8 1 7 10 23","sampleOutput":"5\r\n","questionVideo":"https://www.youtube.com/embed/_yGf2rxwZlA?end=21","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"ec6515dc-6811-4c65-912f-0134b65df120","name":"HashMap and Heap For Intermediate","slug":"hashmap-and-heap-for-intermediate-10002","type":0},{"id":"53e0405f-a507-4490-8ab3-2145a762107e","name":"Largest Subarray With Zero Sum","slug":"largest-subarray-with-zero-sum","type":1}],"next":{"id":"0a5bb13e-289a-42bd-b4ba-8159b2109600","name":"Largest Subarray with Zero Sum MCQ","type":0,"slug":"largest-subarray-with-zero-sum-mcq"},"prev":{"id":"faab5f79-85ab-4cad-9231-293156e4296f","name":"Count Distinct Elements In Every Window Of Size K","type":3,"slug":"count-distinct-elements-in-every-window-of-size-k"}}}`

Editor

Loading...

# Largest Subarray With Zero Sum

easy

1. You are given an array(arr) of integers. 2. You have to find the length of the largest subarray with sum 0.

## Constraints

1 <= N <= 10^6 1 <= arr[i] <= 10^4

## Format

### Input

A number N arr1 arr2.. N numbers

### Output

A number representing the length of largest subarray with zero sum.

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}8 15 -2 2 -8 1 7 10 23```

### Sample Output

```.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}5 ```

Question Video

Discussions

Show Discussion

Related Resources