Question bank › Sliding Window
Dsa Sliding Window Easy

Number of Subarrays with K Different Integers

Given an integer array nums and an integer k, return the number of distinct subarrays in nums that contain exactly k different integers. Input: - The first line contains an integer n (1 ≤ n ≤ 10^5), the size of the array. - The second line contains n integers a_i (1 ≤ a_i ≤ 10^9). - The third line contains an integer k (1 ≤ k ≤ n). Output: - An integer representing the number of subarrays with exactly k distinct integers. Example: Input: 5 1 2 1 2 3 2 Output: 7

Key concepts

sliding_windowarraycounting

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.