{"id":"2874b3b9-d6ed-4853-8c79-cbd94a95bf05","name":"Count Of All Subarrays With Zero Sum","description":"1. You are given an array(arr) of integers.\r\n2. You have to find the count of all subarrays with sum 0.","inputFormat":"A number N\r\narr1\r\narr2.. N numbers","outputFormat":"A number representing the count of all subarrays with sum 0. ","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\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\t\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint n = scn.nextInt();\r\n\t\tint[] arr = new int[n];\r\n\t\tfor (int i = 0; i < n; i++) {\r\n\t\t\tarr[i] = scn.nextInt();\r\n\t\t}\r\n\t\tSystem.out.println(solution(arr));\r\n\r\n\t}\r\n\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"8\r\n15 -2 2 -8 1 7 10 23","sampleOutput":"3\r\n","questionVideo":"https://www.youtube.com/embed/C9-n_H7dsvU?end=9","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":"10f928fb-3026-41cb-8215-3fee79cf1784","name":"Count Of All Subarrays With Zero Sum","slug":"count-of-all-subarrays-with-zero-sum","type":1}],"next":{"id":"0651001b-38ea-40ca-9512-97fae71564f8","name":"Count Of All Subarrays With Zero Sum MCQ","type":0,"slug":"count-of-all-subarrays-with-zero-sum-mcq"},"prev":{"id":"2f4ab4f7-3045-47a3-8d27-662a6323b2fc","name":"Largest Subarray With Zero Sum","type":3,"slug":"largest-subarray-with-zero-sum"}}}

Count Of All Subarrays With Zero Sum

1. You are given an array(arr) of integers. 2. You have to find the count of all subarrays with sum 0.

{"id":"2874b3b9-d6ed-4853-8c79-cbd94a95bf05","name":"Count Of All Subarrays With Zero Sum","description":"1. You are given an array(arr) of integers.\r\n2. You have to find the count of all subarrays with sum 0.","inputFormat":"A number N\r\narr1\r\narr2.. N numbers","outputFormat":"A number representing the count of all subarrays with sum 0. ","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\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\t\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint n = scn.nextInt();\r\n\t\tint[] arr = new int[n];\r\n\t\tfor (int i = 0; i < n; i++) {\r\n\t\t\tarr[i] = scn.nextInt();\r\n\t\t}\r\n\t\tSystem.out.println(solution(arr));\r\n\r\n\t}\r\n\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"8\r\n15 -2 2 -8 1 7 10 23","sampleOutput":"3\r\n","questionVideo":"https://www.youtube.com/embed/C9-n_H7dsvU?end=9","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":"10f928fb-3026-41cb-8215-3fee79cf1784","name":"Count Of All Subarrays With Zero Sum","slug":"count-of-all-subarrays-with-zero-sum","type":1}],"next":{"id":"0651001b-38ea-40ca-9512-97fae71564f8","name":"Count Of All Subarrays With Zero Sum MCQ","type":0,"slug":"count-of-all-subarrays-with-zero-sum-mcq"},"prev":{"id":"2f4ab4f7-3045-47a3-8d27-662a6323b2fc","name":"Largest Subarray With Zero Sum","type":3,"slug":"largest-subarray-with-zero-sum"}}}
plane

Editor


Loading...

Count Of All Subarrays With Zero Sum

medium

1. You are given an array(arr) of integers. 2. You have to find the count of all subarrays 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 count of all subarrays with sum 0.

Example

Sample Input

8 15 -2 2 -8 1 7 10 23

Sample Output

3

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode