Dsa
Arrays
Medium
K-Size Unique Window
Write a function that, given an array of integers and an integer k, finds all subarrays of length k that contain k unique elements. Return these subarrays as a list of lists.
Input:
- The first line contains an integer n (1 <= n <= 1000), the size of the array.
- The second line contains n space-separated integers, the elements of the array.
- The third line contains an integer k (1 <= k <= n), the target size of each subarray.
Output:
- Print a list of lists containing unique subarrays of length k.
Example:
Input:
7
1 2 1 2 3 4 5
3
Output:
[[1, 2, 3], [2, 3, 4], [3, 4, 5]]
Key concepts
arrayssliding-window
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