Mark a Queen’s Attack Board
Reported by candidates from Motive's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Motive flagged this one in February 2025, and it looks harder than it is. Strip the chess dressing and it's a grid-fill problem: for each cell, decide if it shares a row, column, or diagonal with the queen. You build size strings of size characters and return them. If you've got an OA invite for Motive, expect small, clean problems like this where the risk is sloppy indexing, not hard theory. Know the one-line diagonal test and you're done in ten minutes. If your mind goes blank mid-assessment, StealthCoder runs invisibly as a safety net and hands you the solution.
The problem
Given a square board size and a zero-based queen position, return the board as strings. Use Q for the queen, X for every other cell in the queen's row, column, or diagonals, and. for an unattacked cell. Function markQueenAttacks(size: int, queenRow: int, queenCol: int) → String[] Examples Example 1 size = 4 queenRow = 0 queenCol = 0 return = ["QXXX","XX..","X.X.","X..X"] Example 2 size = 3 queenRow = 1 queenCol = 1 return = ["XXX","XQX","XXX"] Constraints 1 <= size <= 200. 0 <= queenRow, queenCol < size.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is the attack test. A cell (r, c) is attacked if r == queenRow, or c == queenCol, or abs(r - queenRow) == abs(c - queenCol). That last check covers both diagonals at once. Loop r from 0 to size-1, c from 0 to size-1, and append Q if it's the queen cell, X if attacked, and a dot otherwise. Check the queen cell first, or it gets overwritten with X. Size tops out at 200, so 40,000 cells is trivial and O(n^2) is the expected answer. Don't bother walking rays out from the queen, it's more code and more bugs. Build each row with a list or StringBuilder and join, not repeated string concatenation in a tight loop. Test against example 2, where the whole 3x3 board is attacked except the queen. If you freeze live, StealthCoder is the hedge that gets the loop and diagonal check on screen.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill Mark a Queen’s Attack Board cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Motive's OA.
Motive reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Mark a Queen’s Attack Board FAQ
How hard is the Motive queen attack board problem really?+
Easy. It's a simulation with a single condition per cell. No data structures, no optimization. The only way to fail is an off-by-one, a wrong diagonal check, or overwriting the queen with an X. Write it in a few lines and test the two examples.
What's the trick to marking diagonals?+
Use abs(r - queenRow) == abs(c - queenCol). If the row distance equals the column distance, the cell sits on one of the queen's diagonals. One expression handles both directions, so you never need to trace rays or special-case the four diagonal directions.
Do I need to worry about performance with size up to 200?+
No. The grid has at most 40,000 cells and you visit each once. O(n^2) time and output size is the floor anyway, since you must return every cell. Just avoid quadratic string concatenation inside a row by using a builder or join.
What edge cases should I test?+
Test size = 1, where the board is just Q. Test the queen in a corner like example 1 and dead center like example 2. Also try a queen on an edge to confirm diagonals only extend in valid directions. Confirm the queen cell prints Q, not X.
How do I prepare for this in 48 hours?+
Practice grid-fill problems where each cell gets a rule-based label. Write the nested loop, the conditional order, and the row-to-string conversion from memory. Then run the two given examples by hand. That covers this problem and most small simulation questions in the same OA.