Find target-heavy sliding windows
Company: Roblox
Role: Machine Learning Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Quick Answer: This question evaluates array manipulation, counting and efficient algorithm design—focusing on the sliding-window technique for detecting and quantifying target occurrences in fixed-size subarrays, and it measures algorithmic efficiency and complexity reasoning.
Constraints
- Windows are contiguous and have length k
- The best window is the earliest one among ties
Examples
Input: ([1, 2, 3, 2, 2], 2, 3)
Expected Output: [[[1, 2, 3], [2, 3, 2], [3, 2, 2]], [2, 3, 2]]
Input: ([1, 1, 1], 2, 2)
Expected Output: [[], None]
Input: ([5], 5, 1)
Expected Output: [[[5]], [5]]
Input: ([1, 2], 1, 3)
Expected Output: [[], None]
Hints
- Maintain the count of target in the current window as it slides by one position.