Escape The Ghosts
specialist · 670 · lc medium +30 · verified · 63.5% accepted · 326 likes · top 66%
Description
You are playing a PAC-MAN style game on an infinite 2-D grid. Your starting position is [0, 0], and you have a destination point target = [xtarget, ytarget] to reach. Several ghosts occupy starting positions given in a 2D array ghosts, where ghosts[i] = [xi, yi] is the starting position of ghost i. All coordinates are integers.
Each turn, you and every ghost may independently move one unit in any cardinal direction (north, east, south, or west) or stay in place. All movements happen simultaneously.
You successfully escape if and only if you arrive at the target before any ghost reaches you. If you and a ghost arrive at the same square (including the target) simultaneously, you do not escape.
Return true if escape is guaranteed regardless of how the ghosts move, otherwise return false.
Example 1:
Example 2:
Example 3:
Code