Question bank › Sliding Window
Dsa Sliding Window Easy

Count Distinct Elements in Every Window

Given an array of integers and a window size k, return the count of distinct elements in every window of size k. Input format: - The first line contains an integer n (length of the array). - The second line contains n space-separated integers (the array). - The third line contains an integer k. Output format: - Print the counts for each window in a single line separated by spaces. Example: Input: 7 1 2 1 3 4 3 5 3 Output: 3 3 3 3 3

Key concepts

sliding_windowarraydistinct

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.