Explained || Java || O(n)
Intuition\n Describe your first thoughts on how to solve this problem. \n\n###### There are 3 different scenarios from the Pacman\'s and the ghost\'s perspectiv
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n###### There are 3 different scenarios from the Pacman\'s and the ghost\'s perspective:\n1. **Pacman\'s distance to the target is equal to the ghost\'s distance to the target**\nThat means both the Pacman and the ghost are going to reach the target at the same time. The description says that if the Pacman reaches the target at the same time as the ghost, Pacman fails to escape.\n2. **Pacman is farther from the target than the ghost**\nThat means the ghost can reach the target before Pacman does. The ghost simply waits at the target to catch the Pacman. Notice the description says "*Each turn, you and all the ghosts may **independently** choose to either move 1 unit in any of the four cardinal directions: north, east, south, or west, or **stay still***". \nAgain; that means the Pacman fails to escape.\n3. **Pacman is closer to the target than the ghost**\nThat means the Pacman can reach the target before the ghost does. So the Pacman escapes. \n\n# Approach\n\n###### Only scenario that the Pacman escapes is if he is the closest to the target. That means we can check all of the ghosts\' distances to the target. If any one of them is closer to the target than the Pacman, or at the same distance, return false, else return true.\n\n###### To calculate the distance of any entity to the target, we can use the Manhattan distance formula. Manhattan distance between the two points $$(x_1, y_1)$$ and $$(x_2, y_2)$$ is:\n$$|x_1 - x_2| + |y_1 - y_2|$$\n\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$ where n is the number of ghosts.\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(1)$$ no additional space is used.\n# Code\n```java []\nclass Solution {\n    public boolean escapeGhosts(int[][] ghosts, int[] target) {\n        // Pacman starts from (0, 0)\n        int pacmanDistanceToTarget = Math.abs(target[0]) + Math.abs(target[1]);\n        for (int[] ghost : ghosts) {\n            int ghostDistanceToTarget = Math.abs(ghost[0] - target[0]) + Math.abs(ghost[1] - target[1]);\n            if (ghostDistanceToTarget <= pacmanDistanceToTarget) return false;\n        }\n        return true;\n    }\n}\n```
['Java']