Question bank › Hashing
Dsa Hashing Warm-up

Count Subarray Distinct Elements

Given a list of integers, count how many distinct elements are in each contiguous subarray of size 'k'. Input Format: - The first line contains two integers, n (the number of elements) and k (the size of subarrays). - The second line contains n space-separated integers. Output Format: - Print each distinct count for the subarrays of size k, space-separated. Example: Input: "6 3\n1 2 1 3 4 2" Output: "2 3 3 2"

Key concepts

hashingarrays

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.