Clean & concise solution , no need different loops !!
Intuition\nInstead of checking from all queens , we can check from the king.\n\nHere i + dir[d] gives us next i and  j + (dir[d + 1]) gives us the next j in the
# Intuition\n**Instead of checking from all queens , we can check from the king.**\n\nHere `i + dir[d]` gives us **next** `i` and  `j + (dir[d + 1])` gives us the **next** `j` in the current direction.\n\nexample , `{dir[0] , dir[1]}` gives us the **update** `{1 , 0}`  which is the required update for **down** direction.\n\n`{dir[1] , dir[2]}` gives us `{ 0 , -1 }` for **up** direction.\n\n`{dir[7] , dir[8]}` gives us `{ 1 , 1 }` for **down-right** direction.\n\nwe can get all **8 directions** like this !!\n# Code\n```\nclass Solution {\npublic:\n    bool isValid(int x , int y ){\n        if( x < 0 or y < 0 or x >= 8 or y >= 8 ) return false ; \n        return true ; \n    }\n    vector<vector<int>> queensAttacktheKing(vector<vector<int>>& queens, vector<int>& king) {\n        vector<vector<int>> Q(8 , vector<int>(8) ) ; // positions of queens ; \n        vector<vector<int>> res ; \n\n        for(auto &pos : queens ){\n            Q[pos[0]][pos[1]] = true ; \n        }\n\n        int dir[9] = { 1 , 0 , -1 , 0 , 1 , -1 , -1 , 1, 1 } ; \n\n        for(int d = 0 ; d < 8 ; d++){\n            int i = king[0] , j = king[1]  ;\n            while( isValid(i  , j )){\n                if(Q[i][j]) {\n                    res.push_back( {i , j} ); \n                    break ; // no other queen can directly hit the king in this direction.\n                }\n                i += dir[d] ;\n                j += dir[d+1] ;\n            }\n        }\n\n        return res ; \n    }\n};\n```
['C++']