![]() |
VOOZH | about |
Given a 2D array queens[][] consisting of coordinates of N queens in an 8 * 8 chessboard and an array king[] denoting the coordinates of the king, the task is to find the queens that are attacking the king
Examples:
Input: queens[][] = {{0, 1}, {1, 0}, {4, 0}, {0, 4}, {3, 3}, {2, 4}}, king[] = {2, 3}
Output: {{0, 1}, {2, 4}, {3, 3}}Explanation:The queens at coordinates {0, 1} and {3, 3} are diagonally attacking the king and the queen at {2, 4} is vertically below the king.
Input: queens[][]] = {{4, 1}, {1, 0}, {4, 0}}, king[] = {0, 0}
Output : {{1, 0}}
Approach Follow the steps below to solve the problem:
Below is the implementation of the above approach:
0 1 2 4 3 3
Time Complexity: O(N), where N is the number of queens
Auxiliary Space: O(N)