Given an array of integers and an integer k, count the number of subarrays having exactly k distinct elements.
Explanation: Subarrays with 2 distinct elements: [1, 2], [2, 1], [1, 2], [2, 3], [1, 2, 1], [2, 1, 2], [1, 2]
Explanation: Subarrays with 1 distinct element: [4], [4], [4], [4], [4, 4], [4, 4], [4, 4], [4, 4, 4], [4, 4, 4], [4, 4, 4, 4]
Process fixed-size subarray/substring
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak