Tap here to switch tabs
Problem
Submissions

Problem: Escape The Ghosts

med
30 min
Try to solve the Escape The Ghosts problem.

Statement

You are playing a game on an infinite 2extD2 ext{D} grid. You begin at the coordinates [0,0][0, 0] and your objective is to reach the destination target =[xexttarget,yexttarget]= [x_{ ext{target}}, y_{ ext{target}}].

There are several ghosts on the grid, where the iextthi^{ ext{th}} ghost begins at the position ghosts[i] =[xi,yi]= [x_i, y_i].

In each turn, you and every ghost may simultaneously move 11 unit in one of the four cardinal directions (north, south, east, or west), or choose to remain in place.

If any ghost occupies the same coordinate as you at any turn (including when you reach the destination), you will be intercepted and lose. You successfully escape only if you can reach target before any ghost can catch you, regardless of the movements the ghosts decide to make.

Return true if it is possible to reach target without being intercepted by any ghost, or false otherwise.

Constraints:

  • 1≤1 \leq ghosts.length ≤100\leq 100

  • ghosts[i].length =2= 2

  • −104≤xi,yi≤104-10^4 \leq x_i, y_i \leq 10^4

  • There can be multiple ghosts in the same location.

  • target.length =2= 2

  • −104≤xexttarget,yexttarget≤104-10^4 \leq x_{ ext{target}}, y_{ ext{target}} \leq 10^4

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Escape The Ghosts

med
30 min
Try to solve the Escape The Ghosts problem.

Statement

You are playing a game on an infinite 2extD2 ext{D} grid. You begin at the coordinates [0,0][0, 0] and your objective is to reach the destination target =[xexttarget,yexttarget]= [x_{ ext{target}}, y_{ ext{target}}].

There are several ghosts on the grid, where the iextthi^{ ext{th}} ghost begins at the position ghosts[i] =[xi,yi]= [x_i, y_i].

In each turn, you and every ghost may simultaneously move 11 unit in one of the four cardinal directions (north, south, east, or west), or choose to remain in place.

If any ghost occupies the same coordinate as you at any turn (including when you reach the destination), you will be intercepted and lose. You successfully escape only if you can reach target before any ghost can catch you, regardless of the movements the ghosts decide to make.

Return true if it is possible to reach target without being intercepted by any ghost, or false otherwise.

Constraints:

  • 1≤1 \leq ghosts.length ≤100\leq 100

  • ghosts[i].length =2= 2

  • −104≤xi,yi≤104-10^4 \leq x_i, y_i \leq 10^4

  • There can be multiple ghosts in the same location.

  • target.length =2= 2

  • −104≤xexttarget,yexttarget≤104-10^4 \leq x_{ ext{target}}, y_{ ext{target}} \leq 10^4