Optimize Oculus Data Streaming with Bandwidth Constraints
Company: Meta
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Quick Answer: This question evaluates a candidate's ability in algorithm design and problem decomposition for array segmentation and interval coverage, focusing on reasoning about cumulative constraints for streaming data and geometric interval intersections.
Oculus: Minimum Bandwidth-Constrained Segments
Constraints
- 0 <= len(frame_sizes) <= 10^5
- 0 <= frame_sizes[i] <= 10^9
- 1 <= bandwidth_limit <= 10^9
- Segments must be contiguous (frames cannot be reordered)
- Return -1 if any single frame exceeds bandwidth_limit
Examples
Input: ([2, 3, 5, 1, 4], 5)
Expected Output: 3
Explanation: Segments [2,3]=5, [5]=5, [1,4]=5. Three segments, each exactly at the limit.
Input: ([1, 1, 1, 1], 10)
Expected Output: 1
Explanation: Total sum 4 <= 10, so the whole array fits in a single segment.
Hints
- Frames cannot be reordered, so a single left-to-right greedy pass is optimal: extend the current segment as long as the running sum stays within the limit.
- Start a new segment exactly when adding the next frame would push the running sum above bandwidth_limit, and reset the running sum to that frame's size.
- Guard the impossible case first: if any individual frame already exceeds bandwidth_limit it can never fit, so return -1.
Circle: Minimum Arrows to Burst All Circles
Constraints
- 0 <= n <= 10^5
- circles[i] = [center, radius] with radius >= 0
- An arrow at p bursts circle i iff center_i - radius_i <= p <= center_i + radius_i
- Circles that touch only at a single boundary point can be burst by one shared arrow
Examples
Input: ([[1, 1], [4, 1], [7, 1]],)
Expected Output: 3
Explanation: Intervals [0,2],[3,5],[6,8] are pairwise disjoint, so three separate arrows are required.
Input: ([[2, 2], [3, 1], [10, 1]],)
Expected Output: 2
Explanation: Intervals [0,4],[2,4],[9,11]. One arrow at 4 bursts the first two; another at 11 bursts the last.
Hints
- Convert each circle [center, radius] into the closed interval [center - radius, center + radius]; the problem becomes the minimum number of points that stab all intervals.
- Sort the intervals by their right endpoint. Greedily shoot each arrow at the right endpoint of the earliest-ending interval not yet burst.
- An interval is already burst by the last arrow if its start is <= the last arrow position; only when start > last_arrow do you need a new arrow.