cpp solution
Runtime: 8 ms, faster than 80.00% of C++ online submissions for Queens That Can Attack the King.\nMemory Usage: 11.2 MB, less than 55.09% of C++ online submissi
Runtime: 8 ms, faster than 80.00% of C++ online submissions for Queens That Can Attack the King.\nMemory Usage: 11.2 MB, less than 55.09% of C++ online submissions for Queens That Can Attack the King.\n```\nclass Solution {\n    //keep moving in same direction and store the first queen encountered(if)\n    void helper(vector<vector<int>>& queens,int i, int j, int inc_i, int inc_j,  vector<vector<int>>& output){\n        if( i < 0 || j < 0 || i >= 8 || j >= 8 ) return ;\n        if(queens[i][j] == 1){\n            output.push_back({i,j});\n            return;\n        }//keep moving in same direction\n        helper(queens,i+inc_i,j+inc_j,inc_i,inc_j,output);\n    }\npublic:\n    vector<vector<int>> queensAttacktheKing(vector<vector<int>>& queens, vector<int>& king) {\n        vector<vector<int>> graph(8,vector<int>(8,0));\n        vector<vector<int>> output;\n        int i, j;\n        for(i = 0; i < queens.size(); i++){\n            graph[queens[i][0]][queens[i][1]] = 1;//denoting queen\n        }\n        vector<int> moveX={-1,-1,-1,0,1,1,1,0};\n        vector<int> moveY={-1,0,1,1,1,0,-1,-1};\n        for(int i = 0; i < 8; i++){        \n           helper(graph, king[0]+moveX[i], king[1]+moveY[i], moveX[i], moveY[i], output);\n        }\n        \n        return output;\n    }\n};
[]