Question bank › Sliding Window
Dsa Sliding Window Hard

Count Unique Elements in Sliding Window

Given an integer array nums and an integer k, return an array containing the count of unique elements in each sliding window of size k. Input: - The first line contains the integer n (1 ≤ n ≤ 10^5): the number of elements in the array. - The second line contains n space-separated integers representing the elements of the array nums. - The third line contains an integer k (1 ≤ k ≤ n): the size of the sliding window. Output: - A space-separated list of integers containing the counts of unique elements for each window. Example: Input: 6 1 2 2 1 3 4 3 Output: 2 3 3

Key concepts

sliding_windowhash_maps

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.