{"id":"a90bb483-ee8b-4569-b07d-df2fd6d313d1","name":"Equivalent Subarrays","description":"1. You are given an array of integers(arr).\r\n2. You have to find the count of equivalent subarrays.\r\n3. A subarray is equivalent if,\r\n count of unique integers in the subarray = count of unique integers in the given array.","inputFormat":"A number N\r\narr1\r\narr2... N numbers","outputFormat":"A number representing count of equivalent subarrays. ","constraints":"1 &lt;= N &lt;= 10^5\r\n-2^31 &lt;= arr[i] &lt;= 2^31-1","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\n\nusing namespace std;\n\nint solution(vector<int> &arr, int k) {\n // write your code here\n \n}\n\nint main() {\n int n;\n cin >> n;\n vector<int> arr(n, 0);\n unordered_set<int> set;\n for (int i = 0 ; i < n; i++) {\n cin >> arr[i];\n set.insert(arr[i]);\n }\n cout << solution(arr, set.size()) - solution(arr, set.size() - 1);\n}\n"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner 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\t\t//write your code here\r\n\t\t\r\n\t}\r\n\r\n\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"5\r\n2 1 3 2 3","sampleOutput":"5\r\n","questionVideo":"https://www.youtube.com/embed/ceRJzjBrhPU?end=43","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":"3e56443e-745a-4d05-b07b-299e921fc4e7","name":"Equivalent Subarrays","slug":"equivalent-subarrays","type":1}],"next":{"id":"348f4e52-b848-4c02-abd5-15b0eaa67ea7","name":"Equivalent Subarrays MCQ","type":0,"slug":"equivalent-subarrays-mcq"},"prev":{"id":"cfa396f2-3257-4579-81aa-0d21d50cd0e0","name":"Count Of Substrings With Exactly K Unique Characters","type":3,"slug":"count-of-substrings-with-exactly-k-unique-characters"}}}

Equivalent Subarrays

1. You are given an array of integers(arr). 2. You have to find the count of equivalent subarrays. 3. A subarray is equivalent if, count of unique integers in the subarray = count of unique integers in the given array.

{"id":"a90bb483-ee8b-4569-b07d-df2fd6d313d1","name":"Equivalent Subarrays","description":"1. You are given an array of integers(arr).\r\n2. You have to find the count of equivalent subarrays.\r\n3. A subarray is equivalent if,\r\n count of unique integers in the subarray = count of unique integers in the given array.","inputFormat":"A number N\r\narr1\r\narr2... N numbers","outputFormat":"A number representing count of equivalent subarrays. ","constraints":"1 &lt;= N &lt;= 10^5\r\n-2^31 &lt;= arr[i] &lt;= 2^31-1","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\n\nusing namespace std;\n\nint solution(vector<int> &arr, int k) {\n // write your code here\n \n}\n\nint main() {\n int n;\n cin >> n;\n vector<int> arr(n, 0);\n unordered_set<int> set;\n for (int i = 0 ; i < n; i++) {\n cin >> arr[i];\n set.insert(arr[i]);\n }\n cout << solution(arr, set.size()) - solution(arr, set.size() - 1);\n}\n"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner 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\t\t//write your code here\r\n\t\t\r\n\t}\r\n\r\n\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"5\r\n2 1 3 2 3","sampleOutput":"5\r\n","questionVideo":"https://www.youtube.com/embed/ceRJzjBrhPU?end=43","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":"3e56443e-745a-4d05-b07b-299e921fc4e7","name":"Equivalent Subarrays","slug":"equivalent-subarrays","type":1}],"next":{"id":"348f4e52-b848-4c02-abd5-15b0eaa67ea7","name":"Equivalent Subarrays MCQ","type":0,"slug":"equivalent-subarrays-mcq"},"prev":{"id":"cfa396f2-3257-4579-81aa-0d21d50cd0e0","name":"Count Of Substrings With Exactly K Unique Characters","type":3,"slug":"count-of-substrings-with-exactly-k-unique-characters"}}}
plane

Editor


Loading...

Equivalent Subarrays

medium

1. You are given an array of integers(arr). 2. You have to find the count of equivalent subarrays. 3. A subarray is equivalent if, count of unique integers in the subarray = count of unique integers in the given array.

Constraints

1 <= N <= 10^5 -2^31 <= arr[i] <= 2^31-1

Format

Input

A number N arr1 arr2... N numbers

Output

A number representing count of equivalent subarrays.

Example

Sample Input

5 2 1 3 2 3

Sample Output

5

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode