Simple Cpp Explained Solution (with Runtime 0ms)
Intuition\n-> As the question description informs us that you and ghosts can only move in four cardinal directions: north, east, south, or west, or can stay sti
# Intuition\n-> As the question description informs us that you and ghosts can only move in four cardinal directions: north, east, south, or west, or can stay still,\n\n-> If the ghost\'s distance to target is shorter, it can move to target and stay there. If the ghost\'s distance to target is longer, the ghost it will never reach you because before it gets to the target you will reach,\n\n-> Now, what if ghost tries to go for you......\nthis case is not possible because there is a limit that we and ghost can only move in only four cardinal directions, so diagonal distance is not possible therefore if it tries to catch you it will move away from the target and you will reach the target before it.\n\n# Approach\n- Simply calculate the number of cells(distance) for you to the target\n- Now calculate distance of each ghost from the target and compare if the distance of ghost from target is less than player return false.\n- If the loop ends without returning that means all of the ghost are away from the player and player will reach the target safelly\n\n# Complexity\n- Time complexity: O(n), 100% better than Online Cpp Solution\n\n- Space complexity: O(n), 61.78% better than Online Cpp Solution\n\n```\nIf you like the Explanation an upvote will be appreciated and if there is any \nerror please comment down \uD83D\uDE0A\uD83D\uDE0A\n```\n\n# Code\n```\nclass Solution {\npublic:\n    bool escapeGhosts(vector<vector<int>>& g, vector<int>& t) {\n        int di=abs(t[0])+abs(t[1]);\n            for(int i=0;i<g.size();i++)\n            {\n                int d=abs(t[0]-g[i][0])+abs((t[1]-g[i][1]));\n                if(d<=di)\n                return false;\n            }\n        return true;\n    }\n};\n```
['Array', 'Math', 'C++']