Find Windows Containing a Target
Company: Roblox
Role: Machine Learning Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Quick Answer: This question evaluates array traversal and interval-containment reasoning, including handling inclusive endpoints, overlapping intervals, and preservation of original ordering.
Constraints
- 0 <= len(windows) <= 100000
- Each window has exactly 2 integers: [start, end]
- -1000000000 <= start, end, target <= 1000000000
- For every window, start <= end
Examples
Input: ([[1, 5], [6, 10], [3, 7], [8, 12]], 6)
Expected Output: [[6, 10], [3, 7]]
Explanation: The target 6 is inside [6, 10] and [3, 7], but not inside [1, 5] or [8, 12].
Input: ([], 4)
Expected Output: []
Explanation: There are no windows to check, so the result is empty.
Input: ([[5, 7], [7, 9], [1, 7], [8, 10]], 7)
Expected Output: [[5, 7], [7, 9], [1, 7]]
Explanation: The target 7 is included when it equals the end or start of a window because endpoints are inclusive.
Input: ([[-5, -1], [-3, 2], [0, 0], [4, 8]], 0)
Expected Output: [[-3, 2], [0, 0]]
Explanation: The target 0 is inside [-3, 2] and [0, 0], but not inside [-5, -1] or [4, 8].
Input: ([[1, 3], [4, 6]], 7)
Expected Output: []
Explanation: The target 7 is not contained in any window.
Input: ([[2, 2]], 2)
Expected Output: [[2, 2]]
Explanation: A single-point window contains the target when start, end, and target are all equal.
Hints
- Each window can be checked independently, so try scanning the list once from left to right.
- Remember that the interval endpoints are inclusive: a window matches when start <= target <= end.