{"id":"6a6065d2-f4ed-4da5-b1df-9425df8ff32a","name":"Count Of Subarrays With Equal Number Of 0s 1s And 2s","description":"1. You are given an array that contains only 0s, 1s, and 2s.\r\n2. You have to find the count of subarrays with equal number of 0s, 1s, and 2s.","inputFormat":"A number N\r\narr1\r\narr2.. N numbers","outputFormat":"A number representing count of subarrays with an equal number of 0s, 1s, and 2s.","constraints":"A number representing the count of subarrays with equal number of 0s, 1s, and 2s.","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\n\nusing namespace std;\n\nint solution(vector<int> &arr, int n) {\n // write your code here\n\n}\n\nint main(){\n int n;\n cin >> n;\n vector<int> arr(n);\n for (int i = 0; i < n; i++) {\n cin >> arr[i];\n }\n cout << solution(arr, 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 \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":"7\r\n0 1 0 2 0 1 0","sampleOutput":"2\r\n","questionVideo":"https://www.youtube.com/embed/fPR4C822JOM?end=19","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":"4574dcad-5688-4daf-9176-a7e5d4dd8ed7","name":"Count Of Subarrays With Equal Number Of 0s 1s And 2s","slug":"count-of-subarrays-with-equal-number-of-0s-1s-and-2s","type":1}],"next":{"id":"df4f15a2-e20b-4b04-8471-abdd24c9d1f7","name":"Count Of Subarrays With Equal Number Of 0s 1s And 2s MCQ","type":0,"slug":"count-of-subarrays-with-equal-number-of-0s-1s-and-2s-mcq"},"prev":{"id":"872c62b6-024d-4032-aad8-885204fe622b","name":"LONGEST SUBARRAY WITH EQUAL NUMBER OF 0s 1s and 2s","type":3,"slug":"longest-subarray-with-equal-number-of-0s-1s-and-2s"}}}

Count Of Subarrays With Equal Number Of 0s 1s And 2s

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

{"id":"6a6065d2-f4ed-4da5-b1df-9425df8ff32a","name":"Count Of Subarrays With Equal Number Of 0s 1s And 2s","description":"1. You are given an array that contains only 0s, 1s, and 2s.\r\n2. You have to find the count of subarrays with equal number of 0s, 1s, and 2s.","inputFormat":"A number N\r\narr1\r\narr2.. N numbers","outputFormat":"A number representing count of subarrays with an equal number of 0s, 1s, and 2s.","constraints":"A number representing the count of subarrays with equal number of 0s, 1s, and 2s.","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\n\nusing namespace std;\n\nint solution(vector<int> &arr, int n) {\n // write your code here\n\n}\n\nint main(){\n int n;\n cin >> n;\n vector<int> arr(n);\n for (int i = 0; i < n; i++) {\n cin >> arr[i];\n }\n cout << solution(arr, 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 \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":"7\r\n0 1 0 2 0 1 0","sampleOutput":"2\r\n","questionVideo":"https://www.youtube.com/embed/fPR4C822JOM?end=19","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":"4574dcad-5688-4daf-9176-a7e5d4dd8ed7","name":"Count Of Subarrays With Equal Number Of 0s 1s And 2s","slug":"count-of-subarrays-with-equal-number-of-0s-1s-and-2s","type":1}],"next":{"id":"df4f15a2-e20b-4b04-8471-abdd24c9d1f7","name":"Count Of Subarrays With Equal Number Of 0s 1s And 2s MCQ","type":0,"slug":"count-of-subarrays-with-equal-number-of-0s-1s-and-2s-mcq"},"prev":{"id":"872c62b6-024d-4032-aad8-885204fe622b","name":"LONGEST SUBARRAY WITH EQUAL NUMBER OF 0s 1s and 2s","type":3,"slug":"longest-subarray-with-equal-number-of-0s-1s-and-2s"}}}
plane

Editor


Loading...

Count Of Subarrays With Equal Number Of 0s 1s And 2s

easy

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

Constraints

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

Format

Input

A number N arr1 arr2.. N numbers

Output

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

Example

Sample Input

7 0 1 0 2 0 1 0

Sample Output

2

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode