Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Queens Attacking the King

XPChallenge Points: 20
levelLevel: Medium

You are given an 8 × 8 chessboard with:
• Multiple black queens ('Q')
• One white king ('K')
You are given:
• queens[i] = [xQueeni, yQueeni] → position of the i-th black queen
• king = [xKing, yKing] → position of the white king
Return all the queens that can directly attack the king —
that is, queens that are the first piece seen in any of the 8 possible directions (vertical, horizontal, or diagonal).
You may return the result in any order.

Example 1:

Input: queens = [[0,1],[1,0],[4,0],[0,4],[3,3],[2,4]] king = [0,0]

Output: [[0,1],[1,0],[3,3]]

Example 2:

Input: queens = [[0,0],[1,1],[2,2],[3,4],[3,5],[4,4],[4,5]] king = [3,3]

Output: [[2,2],[3,4],[4,4]]

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result