Ctrl K

Outrun the Guards

Medium
You stand at (0, 0) on an infinite grid, and the exit is at the cell door = [x, y]. There are guards on the grid: guards[i] = [xi, yi] is where the i-th guard starts. Several guards may share a cell. Each turn takes one unit of time. During a turn, you and every guard simultaneously and independently either move one cell up, down, left or right, or stay put. You escape if you reach the exit before any guard ends up in the same cell as you. If you and a guard arrive at the same cell at the same moment (the exit included), you are caught. Return True if you can escape for sure no matter how the guards move, and False otherwise.
Example 1
guards=[[3, 3], [-2, 0]], door=[0, 2] → True

We are 2 steps from the door. The guard at (3, 3) is 4 steps away from it, and so is the one at (-2, 0). We make it.

Example 2
guards=[[1, 3]], door=[2, 2] → False

Both we and the guard are 4 steps from the door: the guard can just stand at the door and wait, so there is no escape.

Example 3
guards=[[5, -5]], door=[0, 0] → True

We already stand on the door, and the guard is far away.

Constraints
  • 1 ≤ len(guards) ≤ 100
  • len(guards[i]) == 2, len(door) == 2
  • -10⁴ ≤ every coordinate ≤ 10⁴
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsTurn a Square Clockwise MediumPostfix Calculator MediumRoll an Array to the Right MediumPrimes Below a Bound MediumNth Number Built From Given Primes Medium
loading Python…
Input
guards=[[3, 3], [-2, 0]], door=[0, 2]
Expected
True

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