python 3 solution o(n) time, 2 loops
\nclass Solution:\n    def queensAttacktheKing(self, queens: List[List[int]], king: List[int]) -> List[List[int]]:\n        hashTable = {\n            "lu": [],
```\nclass Solution:\n    def queensAttacktheKing(self, queens: List[List[int]], king: List[int]) -> List[List[int]]:\n        hashTable = {\n            "lu": [],\n            "uu": [],\n            "ru": [],\n            "rr": [],\n            "rb": [],\n            "bb": [],\n            "lb": [],\n            "ll": []\n        }\n        i,j = king\n        for qi, qj in queens:\n            #diagonal check\n            if abs(qi-i) == abs(qj-j):\n                # diagonal in upper half\n                if qi < i:\n                    #diagonal in upper left quater\n                    if qj < j:\n                        #checking for minimum distance from king\n                        if hashTable[\'lu\']:\n                            if (abs(i-qi)+abs(j-qj)) > (abs(i-(hashTable[\'lu\'])[0])+abs(j-(hashTable[\'lu\'])[1])):\n                                continue\n                            else:\n                                hashTable[\'lu\'] = [qi,qj]\n                        else:\n                            hashTable[\'lu\'] = [qi, qj]\n                            continue\n                    else:\n                        if hashTable[\'ru\']:\n                            if (abs(i-qi)+abs(j-qj)) > (abs(i-(hashTable[\'ru\'])[0])+abs(j-(hashTable[\'ru\'])[1])):\n                                continue\n                            else:\n                                hashTable[\'ru\'] = [qi,qj]\n                        else:\n                            hashTable[\'ru\'] = [qi, qj]\n                            continue\n                else:\n                    if qj < j:\n                        if  hashTable[\'lb\']:\n                            if (abs(i-qi)+abs(j-qj)) > (abs(i-(hashTable[\'lb\'])[0])+abs(j-(hashTable[\'lb\'])[1])):\n                                continue\n                            else:\n                                hashTable[\'lb\'] = [qi,qj]\n                        else:\n                            hashTable[\'lb\'] = [qi, qj]\n                            continue\n                    else:\n                        if  hashTable[\'rb\']:\n                            if (abs(i-qi)+abs(j-qj)) > (abs(i-(hashTable[\'rb\'])[0])+abs(j-(hashTable[\'rb\'])[1])):\n                                continue\n                            else:\n                                hashTable[\'rb\'] = [qi,qj]\n                        else:\n                            hashTable[\'rb\'] = [qi, qj]\n                            continue\n                            \n                    \n            \n            # horizontal check\n            if qi == i:\n                if qj < j:\n                    if hashTable[\'ll\']:\n                        if (abs(i-qi)+abs(j-qj)) > (abs(i-(hashTable[\'ll\'])[0])+abs(j-(hashTable[\'ll\'])[1])):\n                                continue\n                        else:\n                                hashTable[\'ll\'] = [qi,qj]\n                    else:\n                        hashTable[\'ll\'] = [qi, qj]\n                        continue\n                else:\n                    if hashTable[\'rr\']:\n                        if (abs(i-qi)+abs(j-qj)) > (abs(i-(hashTable[\'rr\'])[0])+abs(j-(hashTable[\'rr\'])[1])):\n                                continue\n                        else:\n                                hashTable[\'rr\'] = [qi,qj]\n                    else:\n                        hashTable[\'rr\'] = [qi, qj]\n                        continue\n            \n            # vertical check\n            if qj == j:\n                if qi < i:\n                    if  hashTable[\'uu\']:\n                        if (abs(i-qi)+abs(j-qj)) > (abs(i-(hashTable[\'uu\'])[0])+abs(j-(hashTable[\'uu\'])[1])):\n                                continue\n                        else:\n                                hashTable[\'uu\'] = [qi,qj]\n                    else:\n                        hashTable[\'uu\'] = [qi, qj]\n                        continue\n                else:\n                    if  hashTable[\'bb\']:\n                        if (abs(i-qi)+abs(j-qj)) > (abs(i-(hashTable[\'bb\'])[0])+abs(j-(hashTable[\'bb\'])[1])):\n                                continue\n                        else:\n                                hashTable[\'bb\'] = [qi,qj]\n                    else:\n                        hashTable[\'bb\'] = [qi, qj]\n                        continue\n        ans= []\n        for value in hashTable.values():\n            if value:\n                ans.append(value)\n        return ans\n\t\t```
['Python', 'Python3']