MEDIUMasked at 1 company

Queens That Can Attack the King

A medium-tier problem at 72% community acceptance, tagged with Array, Matrix, Simulation. Reported in interviews at Media.net and 0 others.

Founder's read

You're given a board with a king and some queens, and you need to find which queens can attack the king. It's a 2D grid problem that feels like it should be straightforward, but the coordinate geometry and the directional patterns trip up candidates who over-engineer. Media.net has asked this one. If you blank on the approach during the assessment and need a fast working solution, StealthCoder reads the board state and surfaces the answer in seconds while the proctor sees nothing.

Companies asking
1
Difficulty
MEDIUM
Acceptance
72%

Companies that ask "Queens That Can Attack the King"

If this hits your live OA

Queens That Can Attack the King is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by a senior engineer who knows the OA is theater. This is the script.

Get StealthCoder
What this means

The trick is recognizing that a queen attacks in 8 directions: up, down, left, right, and four diagonals. You iterate through all queens, then check each direction until you hit a boundary or the king. Most candidates write bloated code checking distance separately or fail to handle diagonal slopes correctly. The pattern is simple: for each queen, scan outward in all 8 cardinal and diagonal directions until you either find the king (it can attack) or hit the edge (it can't). This is a simulation problem disguised as a search problem. Common pitfall: trying to precompute attack zones instead of just scanning from each queen toward the king directly. That's slower and error-prone. StealthCoder has the directional iteration locked down, so if you get stuck on the geometry during a live OA, you've got the solution.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Queens That Can Attack the King recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by a senior engineer who knows the OA is theater. This is the script. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Queens That Can Attack the King interview FAQ

How do I check all 8 directions from a queen efficiently?+

Use two nested loops or eight separate direction pairs: (0,1), (0,-1), (1,0), (-1,0), (1,1), (1,-1), (-1,1), (-1,-1). For each direction, move step by step from the queen until you hit the boundary or find the king. Stop early once you hit anything. No need to precompute.

Is this problem still asked at top companies?+

Media.net has confirmed it. The acceptance rate is strong at 72%, suggesting it's a fair filter problem. Not a trick question, but definitely an OA staple for companies testing basic 2D grid navigation and directional logic.

What's the difference between this and a standard grid path problem?+

This is pure simulation. You're not searching or optimizing. You scan in fixed directions and stop at the first obstacle or boundary. Grid path problems involve finding the shortest route or navigating obstacles. Here, you're just checking line-of-sight in 8 fixed rays.

Will I time out if I check every direction naively?+

No. The board is bounded (8x8 or small), and you check at most 8 directions per queen. Stop scanning a direction as soon as you hit a piece or edge. Even naive iteration is fast enough. Optimization is premature here.

How should I handle the diagonal directions?+

Diagonals move by (±1, ±1). Use a loop that increments row and column together by the same offset: row += dr, col += dc where (dr, dc) is one of the four diagonal pairs. Check bounds at each step. It's the same pattern as the cardinal directions, just two coordinates change instead of one.

Want the actual problem statement? View "Queens That Can Attack the King" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.