Ctrl K

Across the Park Around the Ponds

Hard
A park is a rectangle with its bottom-left corner at (0, 0) and its top-right corner at (width, height). There are round ponds in and around it: ponds[i] = [x, y, r] is a pond centred at (x, y) with radius r. A pond may stick out of the park partly or completely. You need to walk from the corner (0, 0) to the corner (width, height) along any curve that: - lies entirely inside the park and touches its border only at those two corners; - never enters any pond and never even touches its shore. Return True if such a walk exists, and False otherwise.
Example 1
width=4, height=3, ponds=[[2, 2, 1]] → True

The pond touches only the top side of the park. You can pass below it, near the bottom side, and climb to the corner (4, 3) to the right of the pond.

Example 2
width=4, height=4, ponds=[[2, 1, 1], [2, 3, 1]] → False

The lower pond touches the bottom side of the park, the upper one touches the top side, and they touch each other at (2, 2). Together they wall the park off, so there is no way around.

Example 3
width=5, height=5, ponds=[[6, 6, 2]] → False

The corner (5, 5) lies inside the pond, so it cannot be reached.

Constraints
  • 3 ≤ width, height ≤ 10⁹
  • 1 ≤ len(ponds) ≤ 1000
  • len(ponds[i]) == 3
  • 1 ≤ x, y, r ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsLongest Firework Chain MediumCrossing at High Tide HardFill a Single Cell HardOne-Swap Word Families HardWhich Machine to Cure Hard
loading Python…
Input
width=4, height=3, ponds=[[2, 2, 1]]
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 108 tests on the server, hidden ones included.