Question bank › Sliding Window
Dsa Sliding Window Easy

Count Distinct Elements in Window

You have an array of integers and a sliding window of a fixed size. Count the number of distinct elements in each window. Input the array size followed by the elements of the array and the window size in one line (e.g., '5 1 2 1 3 4 2'). Output the counts of distinct elements for each sliding window. Example: Input: 6 1 2 1 2 3 4 2 3 Output: 2 3 4 3

Key concepts

sliding_windowcountingarray

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 Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.