Dsa
Sliding Window
Easy
The Unique Batch
A factory produces components with serial numbers. To ensure quality, the testing machine checks batches of exactly W consecutive components. A batch is only 'valid' if every component in that batch has a unique serial number. Count how many valid batches exist in the production stream.
Input Format:
- The first line contains two integers: W (the batch size) and N (the total number of components).
- The second line contains N space-separated integers representing the serial numbers.
Output Format:
- Print the number of valid batches.
Example:
Input:
3 6
1 2 3 2 1 4
Output:
3
Explanation: The valid batches are [1, 2, 3], [3, 2, 1], and [2, 1, 4]. [2, 3, 2] is invalid due to duplicate 2s.
Key concepts
sliding_windowhash_mapuniqueness
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