Question bank › Sliding Window
Dsa Sliding Window Easy

Count Distinct Numbers in Sliding Window

Given an array of integers and an integer K, return the count of distinct integers in every sliding window of size K. Input: - The first line contains an integer N (1 <= N <= 10^5) - the number of elements in the array. - The second line contains N space-separated integers representing the array elements. - The third line contains the integer K (1 <= K <= N). Output: - Output N - K + 1 integers representing the count of distinct integers for every sliding window of size K. Example: Input: 6 1 2 1 3 4 2 3 Output: 3 2 3 3

Key concepts

sliding_windowhash_mapcounting

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.