Radar Barrier Crossing
Updated
Problem statement
A rectangular area spans 0 <= x <= width and 0 <= y <= height. Each row [x, y, radius] in radars describes a circular detection region centered inside the rectangle, including the circle’s boundary.
An object wants to travel continuously from the left wall to the right wall without entering or touching any detection region. Two radar regions belong to the same connected group if they overlap or touch, either directly or through a chain of other radars.
A left-to-right undetected crossing is impossible exactly when one connected radar group touches both the bottom wall and the top wall. Return true when an undetected crossing is possible; otherwise return false.
Function
canCrossUndetected(width: int, height: int, radars: int[][]) → booleanExamples
Example 1
width = 10height = 10radars = [[5,2,3],[5,8,3]]return = falseThe two circles touch. The lower one reaches the bottom wall and the upper one reaches the top wall, so their component forms a complete barrier.
Example 2
width = 12height = 10radars = [[2,2,2],[6,2,2],[10,2,2]]return = trueThe horizontal component touches the bottom wall but not the top wall, so it does not separate the left and right walls.
Example 3
width = 8height = 6radars = []return = trueWith no detection regions, an undetected left-to-right route exists.
Constraints
1 <= width, height <= 10^9.0 <= radars.length <= 1000.- Every radar row contains exactly
[x, y, radius]. 0 <= x <= widthand0 <= y <= height.0 <= radius <= 10^9.- Circle overlap, tangency, and wall contact are inclusive.
- Use 64-bit arithmetic for squared-distance comparisons.
More Snap Inc. interview questions
- Render an Org Chart and Find Skip-Level PairsONSITE INTERVIEW · Seen Nov 2026
- Peak of an Increasing-Then-Decreasing ArrayONSITE INTERVIEW · Seen Oct 2026
- Number of Closed IslandsONSITE INTERVIEW · Seen Oct 2026
- Sort Characters by FrequencyONSITE INTERVIEW · Seen Sep 2026
- Dictionary Records to an Editable XML TreeONSITE INTERVIEW · Seen Aug 2026
- Metric Counter with a Fake ClockONSITE INTERVIEW · Seen Aug 2026
- ID Allocator with Assign and ReleasePHONE SCREEN · Seen Nov 2026
- Basic Calculator IIPHONE SCREEN · Seen Oct 2026
- Stream Cluster Max and MedianPHONE SCREEN · Seen Oct 2026
- LRU Cache with Thread-Safety Follow-UpPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Accounts MergeOracle · ONSITE INTERVIEWOracle interview questions
- Count Connected Point ClustersGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Number of Islands IIAmazon · ONSITE INTERVIEW
- Find All People With SecretIDFC Bank · ONSITE INTERVIEWIDFC Bank interview questions
- Group Linked Merchant RecordsStripe · PHONE SCREENStripe interview questions
- Group Sparse Points by Distance ThresholdNuro · PHONE SCREENNuro interview questions
- Count Islands in a Binary GridApple · PHONE SCREENApple interview questions
- Detonate Bombs with Chain ReactionsAirbnb · PHONE SCREENAirbnb interview questions
- Recoverable Elements from Range-Sum MeasurementsEthos Life · OA
- Number of Islands IISpaceX · PHONE SCREENSpaceX interview questions