[Python3] 2 approaches
\n\nclass Solution:\n    def queensAttacktheKing(self, queens: List[List[int]], king: List[int]) -> List[List[int]]:\n        ans = []\n        x, y = king\n   
\n```\nclass Solution:\n    def queensAttacktheKing(self, queens: List[List[int]], king: List[int]) -> List[List[int]]:\n        ans = []\n        x, y = king\n        queens = {(x, y) for x, y in queens}\n        for dx in (-1, 0, 1):\n            for dy in (-1, 0, 1):\n                for k in range(1, 8):\n                    xx, yy = x+k*dx, y+k*dy\n                    if (xx, yy) in queens: \n                        ans.append([xx, yy])\n                        break \n        return ans \n```\n\n```\nclass Solution:\n    def queensAttacktheKing(self, queens: List[List[int]], king: List[int]) -> List[List[int]]:\n        ans = [[inf]*2 for _ in range(8)]\n        xx, yy = king\n        fn = lambda x: max(abs(x[0]-xx), abs(x[1]-yy))\n        for x, y in queens: \n            if x == xx: # same row \n                if y < yy: ans[0] = min(ans[0], (x, y), key=fn)\n                else: ans[1] = min(ans[1], (x, y), key=fn)\n            elif yy == y: # same column\n                if x < xx: ans[2] = min(ans[2], (x, y), key=fn)\n                else: ans[3] = min(ans[3], (x, y), key=fn)\n            elif xx-yy == x-y: # same diagonoal\n                if x < xx: ans[4] = min(ans[4], (x, y), key=fn)\n                else: ans[5] = min(ans[5], (x, y), key=fn)\n            elif xx+yy == x+y: # same anti-diagonal\n                if x < xx: ans[6] = min(ans[6], (x, y), key=fn)\n                else: ans[7] = min(ans[7], (x, y), key=fn)\n        \n        return [[x, y] for x, y in ans if x < inf]\n```
['Python3']