Java | Simple | Explained
Idea:\n Problem doesn\'t ask whether any ghost can catch pacman or not, it asks whether any ghost can reach target before or at the same time as pacman. As long
**Idea:**\n* Problem doesn\'t ask whether any ghost can catch pacman or not, it asks whether any ghost can reach target before or at the same time as pacman. As long as this happens, pacman can\'t escape\n>T/S: O(n)/O(1), where n = size(ghosts)\n```\nprivate static final int[] ORIGIN = {0, 0};\n\npublic boolean escapeGhosts(int[][] ghosts, int[] target) {\n\tvar pacmanDistance = getTargetDistance(ORIGIN, target);\n\treturn Arrays.stream(ghosts)\n\t\t\t\t .noneMatch(ghost -> getTargetDistance(ghost, target) <= pacmanDistance);\n}\n\n/**\n * @return Manhattan distance between source and destination\n */\nprivate int getTargetDistance(int[] source, int[] destination) {\n\treturn Math.abs(destination[0] - source[0]) + Math.abs(destination[1] - source[1]);\n}\n```\n***Please upvote if this helps***
['Java']