Imagine a chess battle where multiple black queens are strategically positioned on an 8ร8 chessboard, all eyeing a single white king. Your mission? Identify which queens pose an immediate threat!
You're given:
queens- A 2D array wherequeens[i] = [x, y]represents the position of the i-th black queenking- An array[x, y]representing the white king's position
A queen can attack the king if they share the same row, column, or diagonal with no pieces blocking the path. Return the coordinates of all queens that can directly attack the king.
Example: If the king is at [0,1] and queens are at [[0,0], [1,1], [2,2]], then queens at [0,0] (same row) and [1,1] (diagonal) can attack, but [2,2] cannot because [1,1] blocks the diagonal path.
Input & Output
Visualization
Time & Space Complexity
For each of n queens, we check all other n queens to see if they block the path
Only using variables for iteration and result storage
Constraints
- 1 โค queens.length โค 63
- queens[i].length == 2
- 0 โค queens[i][j] < 8
- king.length == 2
- 0 โค king[0], king[1] < 8
- All given positions are unique
- The king and queens are placed on a standard 8ร8 chessboard