Question bank › Arrays
Dsa Arrays Medium

K-Count Distinct Elements

Given an array of integers and a positive integer k, find the count of distinct integers in every contiguous subarray of size k. The output should be a single line with counts for each subarray separated by spaces. The input consists of a single line with integers followed by the integer k. Example Input: 1 2 1 3 4 3 3 Example Output: 2 3 3 2

Key concepts

arrayssubarraysdistinct

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.