Fun brainteaser O(1) Time and O(1) Space Approach Simplifies to Manhattan Distance Computation
Complexity\n- Time complexity:\nO(1)\n\n- Space complexity:\nO(1)\n\n# Code\npython3 []\n\'\'\'\nURL := https://leetcode.com/problems/escape-the-ghosts/descript
# Complexity\n- Time complexity:\n$$O(1)$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```python3 []\n\'\'\'\nURL := https://leetcode.com/problems/escape-the-ghosts/description/\n789. Escape The Ghosts\n\nSimplify the infinite paths : you can always play "optimally" and move some "1 cell" away from the ghost\n\n\'\'\'\nclass Solution:\n    def escapeGhosts(self, ghosts: List[List[int]], target: List[int]) -> bool:\n        canEscape = True\n        pacman = [0,0]\n        pacDistToTarget = self.getDist(pacman,target)\n        for ghost in ghosts:\n            ghostDistToTarget = self.getDist(ghost,target)\n            if(ghostDistToTarget <= pacDistToTarget):\n                canEscape = False\n                break\n        return canEscape\n\n    def getDist(self, piece: List[int], target: List[int]) -> int:\n        x1 = piece[0]\n        x2 = target[0]\n        y1 = piece[1]\n        y2 = target[1]\n        return abs(x2-x1) + abs(y2-y1)\n\n        \n```
['Array', 'Math', 'C++', 'Python3']