Is the Segment From 0 to 50 Fully Contaminated After Each Landing Point?
WaymoSite Reliability Engineer · OnsiteLast updated
Points land one at a time on the segment from 0 to 50, each contaminating an interval of length 1 around it; after each landing, report whether the whole segment is contaminated. Tests interval union maintenance, exact boundary handling and efficient updates.
Consider the number line segment [0, 50]. Points keep landing on it one at a time. Each point contaminates the region within 0.5 of where it lands, that is, an interval of length 1 centered on the point. Once part of the line is contaminated it stays contaminated forever. Points can land anywhere on the segment, and the regions of different points may overlap.
The interview asked you to design a function that is called once per landing point (given as a floating-point number) and returns a boolean telling whether the entire segment [0, 50] is now contaminated. In this console version you receive all landing points in order and return the answer after each one.
Function Signature
def fully_contaminated_after_each(points: list[float]) -> list[bool]:
Rules
- A point landing at
pcontaminates the closed interval[p - 0.5, p + 0.5], clipped to[0, 50]. - The segment is fully contaminated when every real number in
[0, 50], including both endpoints, lies in at least one contaminated interval. Two intervals that touch at a single point leave no gap between them. - The
i-th output isTrueif the segment is fully contaminated after processingpoints[0]throughpoints[i], andFalseotherwise. Once an output isTrue, all later outputs areTrue. - Every landing point has at most two digits after the decimal point. Decide coverage using the exact decimal values as written (for example,
0.35 + 0.5equals exactly0.85), not values affected by floating-point rounding.
Constraints
1 <= len(points) <= 10^50 <= points[i] <= 50- Each
points[i]has at most two digits after the decimal point. - Points may repeat.
Examples
Example 1
- Input:
points = [25.0, 10.3] - Output:
[False, False] - Explanation: Only
[24.5, 25.5]and[9.8, 10.8]are contaminated.
Example 2
- Input:
pointsis the 49 values0.5, 1.5, 2.5, ..., 48.5in increasing order, followed by49.6, followed by49.5(51 points in total). - Output: 49 values
False, thenFalse, thenTrue. - Explanation: The first 49 points contaminate
[0, 49]exactly. The point49.6adds[49.1, 50](clipped at 50), which still leaves the gap between 49 and 49.1. The point49.5adds[49, 50]and closes it.
Example 3
- Input:
points = [0.2, 49.8] - Output:
[False, False] - Explanation: The contaminated intervals
[0, 0.7]and[49.3, 50]cover both ends, but the middle is still clean.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.