![]() |
VOOZH | about |
Given an array arr[] consisting of integers, find the number of subarrays of arr[] that contain exactly the same number of distinct elements as the entire array.
Examples:
Input: arr[] = [1, 2, 1, 3]
Output: 2
Explanation: The array has 3 distinct elements. Subarrays with exactly 3 distinct elements are:
[1, 2, 1, 3], [2, 1, 3]Input: arr[] = [4, 3, 4, 3, 5]
Output: 3
Explanation: The array has 3 distinct elements. Subarrays with exactly 3 distinct elements are:
[4, 3, 4, 3, 5], [3, 4, 3, 5], [4, 3, 5]
Table of Content
2
2