`{"id":"1770cbb7-1c6e-44a8-97d7-ddaa96fb031b","name":"Count Of Subarrays With Equal Number Of Zeroes And Ones","description":"1. You are given an array that contains only 0s and 1s.\r\n2. You have to find the count of subarrays with equal number of 0s and 1s.","inputFormat":"A number N\r\narr1\r\narr2.. N numbers","outputFormat":"A number representing count of subarrays with equal number of 0s and 1s.","constraints":"1 &lt;= N &lt;= 10^5\r\n0 &lt;= arr[i] &lt;= 1","sampleCode":{"cpp":{"code":"#include \"bits/stdc++.h\"\nusing namespace std;\n\nint solution(vector<int> &v){\n //Write your code here.\n}\n\n\nint main(){\n int n;cin>> n;\n vector<int> v(n);\n for(int i=0;i<n;i++){\n cin >> v[i];\n }\n cout << solution(v) << endl;\n\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static int solution(int[] arr) {\r\n // write your code here\r\n\r\n return 0;\r\n }\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int[] arr = new int[n];\r\n for (int i = 0; i < n; i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n System.out.println(solution(arr));\r\n }\r\n\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"6\r\n0 1 1 0 1 1","sampleOutput":"4\r\n","questionVideo":"https://www.youtube.com/embed/svMdY6wlQ6I?end=12","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":"ae678e3c-731b-40df-92b7-bc5b3defe7b3","name":"Count Of Subarrays With Equal Number Of Zeroes And Ones","slug":"count-of-subarrays-with-equal-number-of-zeroes-and-ones","type":1}],"next":{"id":"c57795ac-92dd-42cc-b414-96e71136e19e","name":"Count Of Subarrays With Equal Number Of Zeroes And Ones MCQ","type":0,"slug":"count-of-subarrays-with-equal-number-of-zeroes-and-ones-mcq"},"prev":{"id":"adb0978d-d53c-465b-9fc2-23e2d79d62eb","name":"Longest Subarray With Equal Number Of Zeroes And Ones","type":3,"slug":"longest-subarray-with-equal-number-of-zeroes-and-ones"}}}`

# Count Of Subarrays With Equal Number Of Zeroes And Ones

1. You are given an array that contains only 0s and 1s. 2. You have to find the count of subarrays with equal number of 0s and 1s.

`{"id":"1770cbb7-1c6e-44a8-97d7-ddaa96fb031b","name":"Count Of Subarrays With Equal Number Of Zeroes And Ones","description":"1. You are given an array that contains only 0s and 1s.\r\n2. You have to find the count of subarrays with equal number of 0s and 1s.","inputFormat":"A number N\r\narr1\r\narr2.. N numbers","outputFormat":"A number representing count of subarrays with equal number of 0s and 1s.","constraints":"1 &lt;= N &lt;= 10^5\r\n0 &lt;= arr[i] &lt;= 1","sampleCode":{"cpp":{"code":"#include \"bits/stdc++.h\"\nusing namespace std;\n\nint solution(vector<int> &v){\n //Write your code here.\n}\n\n\nint main(){\n int n;cin>> n;\n vector<int> v(n);\n for(int i=0;i<n;i++){\n cin >> v[i];\n }\n cout << solution(v) << endl;\n\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static int solution(int[] arr) {\r\n // write your code here\r\n\r\n return 0;\r\n }\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int[] arr = new int[n];\r\n for (int i = 0; i < n; i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n System.out.println(solution(arr));\r\n }\r\n\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"6\r\n0 1 1 0 1 1","sampleOutput":"4\r\n","questionVideo":"https://www.youtube.com/embed/svMdY6wlQ6I?end=12","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":"ae678e3c-731b-40df-92b7-bc5b3defe7b3","name":"Count Of Subarrays With Equal Number Of Zeroes And Ones","slug":"count-of-subarrays-with-equal-number-of-zeroes-and-ones","type":1}],"next":{"id":"c57795ac-92dd-42cc-b414-96e71136e19e","name":"Count Of Subarrays With Equal Number Of Zeroes And Ones MCQ","type":0,"slug":"count-of-subarrays-with-equal-number-of-zeroes-and-ones-mcq"},"prev":{"id":"adb0978d-d53c-465b-9fc2-23e2d79d62eb","name":"Longest Subarray With Equal Number Of Zeroes And Ones","type":3,"slug":"longest-subarray-with-equal-number-of-zeroes-and-ones"}}}`

Editor

# Count Of Subarrays With Equal Number Of Zeroes And Ones

easy

1. You are given an array that contains only 0s and 1s. 2. You have to find the count of subarrays with equal number of 0s and 1s.

## Constraints

1 <= N <= 10^5 0 <= arr[i] <= 1

## Format

### Input

A number N arr1 arr2.. N numbers

### Output

A number representing count of subarrays with equal number of 0s and 1s.

## 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;}6 0 1 1 0 1 1```

### 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;}4 ```

Question Video

Discussions

Show Discussion

Related Resources