Dsa
Sliding Window
Easy
The Variety Stream
A streaming service wants to curate a 'Variety Pack' of video clips. You are given a list of clip IDs (integers) and their durations in seconds. Find the SMALLEST continuous window of clips that contains at least K distinct clip IDs, provided that the total duration of the window does not exceed T seconds. If no such window exists, output -1.
Example:
Input:
6 3 15
1 2 1 3 2 4
5 5 5 5 5 5
Output:
3
Explanation: K=3, T=15. Clips [2, 1, 3] from index 1 to 3 have 3 distinct IDs and total duration 15. Length 3.
Key concepts
sliding_windowhash_mapoptimization
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