Check if the Rectangle Corner Is Reachable - Problem

You are given two positive integers xCorner and yCorner, and a 2D array circles, where circles[i] = [x_i, y_i, r_i] denotes a circle with center at (x_i, y_i) and radius r_i.

There is a rectangle in the coordinate plane with its bottom left corner at the origin (0, 0) and top right corner at the coordinate (xCorner, yCorner).

You need to check whether there is a path from the bottom left corner to the top right corner such that:

  • The entire path lies inside the rectangle
  • Does not touch or lie inside any circle
  • Touches the rectangle only at the two corners

Return true if such a path exists, and false otherwise.

Input & Output

Example 1 — No Blocking Path
$ Input: xCorner = 3, yCorner = 3, circles = [[2,1,1]]
Output: true
💡 Note: Single circle at (2,1) with radius 1 doesn't block the path from (0,0) to (3,3). We can go around it.
Example 2 — Path Completely Blocked
$ Input: xCorner = 3, yCorner = 3, circles = [[1,1,2]]
Output: false
💡 Note: Circle at (1,1) with radius 2 covers both corners (0,0) and (3,3), making any path impossible.
Example 3 — Multiple Small Circles
$ Input: xCorner = 2, yCorner = 2, circles = [[1,0,1],[0,1,1]]
Output: false
💡 Note: Two circles create a barrier: one blocks right movement from (0,0), other blocks upward movement, preventing any path to (2,2).

Constraints

  • 1 ≤ xCorner, yCorner ≤ 109
  • 0 ≤ circles.length ≤ 1000
  • circles[i].length == 3
  • 1 ≤ xi, yi, ri ≤ 109

Visualization

Tap to expand
Rectangle Corner Reachability Problem(0,0)(xCorner,yCorner)STARTGOALCircleCirclePossible Path?Solution Approaches1. Path Finding (DFS/BFS):Directly search for valid path2. Union-Find (Optimal):Check if circles block boundariesKey Insight:If obstacles connect opposite sides,no path can exist!Return true if path exists, false if blocked
Understanding the Visualization
1
Rectangle Setup
Rectangle from (0,0) to (xCorner,yCorner) with circular obstacles
2
Path Analysis
Check if circles block all possible paths
3
Result
Return true if any path exists, false if completely blocked
Key Takeaway
🎯 Key Insight: If circles form a continuous barrier connecting opposite boundaries, no path can exist
Asked in
Google 15 Meta 12 Amazon 8
9.0K Views
Medium Frequency
~35 min Avg. Time
245 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen