Description
You are at origin, want to reach target. Ghosts try to catch you. All move 1 unit per step. Return true if you can reach target first.
Examples
Input:
ghosts = [[1,0],[0,3]], target = [0,1]Output:
trueExplanation:
Your Manhattan distance to target is 1. Ghost at [1,0] has distance 2, ghost at [0,3] has distance 4. You arrive first.
Input:
ghosts = [[1,0]], target = [2,0]Output:
falseExplanation:
For ghosts = [[1,0]], target = [2,0], the answer is false because the escape the ghosts condition is not met.
Input:
ghosts = [[2,2],[-1,4],[3,-2]], target = [1,1]Output:
falseExplanation:
You start at [0,0] and need 2 steps to reach [1,1]. Ghost at [2,2] also needs 2 steps, so the tie means escape fails.
Constraints
- •
1 ≤ ghosts.length ≤ 100