Apply a Reversi Move
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Amazon reportedly served this one in September 2026, and it's a simulation problem wearing a board game costume. Strip the Reversi flavor and it's an eight-direction grid walk: from the target cell, scan each direction, collect opponent pieces, and flip them only if the run ends on your own piece. No fancy algorithm. The risk is sloppy bookkeeping under a timer. If you blank on the direction logic during the live OA, StealthCoder is the invisible safety net that reads the problem and hands you a working solution.
The problem
Given a Reversi board board, a zero-based target cell row, col, and a player player equal to B or W, apply exactly one move. A direction captures pieces when one or more consecutive opponent pieces start next to the target and are followed, in that same direction, by one of the current player's pieces. A legal move places the player's piece and flips every captured line in all eight directions. If the target is occupied or no direction captures an opponent piece, return the original board unchanged. Do not modify the input strings. Function applyReversiMove(board: String[], row: int, col: int, player: char) → String[] Examples Example 1 board = ["....",".WB.","...."] row = 1 col = 3 player = "W" return = ["....",".WWW","...."] The new white piece at column 3 brackets the black piece with the existing white piece at column 1. Example 2 board = ["..B..","..W..","BW.WB","..W..","..B.."] row = 2 col = 2 player = "B" return = ["..B..","..B..","BBBBB","..B..","..B.."] The move captures one white piece in each cardinal direction. Example 3 board = ["...","...","..."] row = 1 col = 1 player = "B" return = ["...","...","..."] No opponent line is bracketed, so the move is invalid and the board remains unchanged. Constraints 1 <= board.length, board[i].length <= 50. Every row has the same length and contains only., B, or W. 0 <= row < board.length and 0 <= col < board[0].length. player is B or W.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The whole problem reduces to a direction-vector loop. Define eight (dr, dc) pairs. For each one, step from the target, count consecutive opponent pieces, and stop at the first non-opponent cell. If that stopping cell is in bounds and holds the current player's piece, and you counted at least one opponent piece, flip that run. Track whether any direction captured. If none did, or the target is already occupied, return the original board. The pitfalls are predictable. Forgetting the bounds check, treating an empty cell as a bracket, flipping before confirming the bracket, and mutating the input strings. Convert rows to char arrays on a copy, then join back to strings. Complexity is tiny, at most 8 times 50 steps. Write the flip as a second pass over the verified run, not during the scan. StealthCoder is your hedge if the loop structure slips away mid-assessment.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Apply a Reversi Move 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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as flip game. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Amazon's OA.
Amazon reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Apply a Reversi Move FAQ
How hard is Apply a Reversi Move really?+
Easy to medium. There's no clever algorithm, just careful implementation. The difficulty is handling eight directions, bounds, and the no-capture case without bugs. If you've written a grid neighbor loop before, you can finish this quickly.
What's the trick to solving it?+
Use a list of eight direction vectors and write one scan function. Walk while cells are opponent pieces, then check whether the next cell is yours. Only flip after the bracket is confirmed. Repeat for each direction and track whether anything flipped.
What's the most common bug?+
Treating the run as valid when it ends at an empty cell or the board edge. A capture needs at least one opponent piece followed by your own piece. Missing either condition flips pieces that shouldn't change.
How do I avoid modifying the input?+
Strings are immutable in many languages anyway, so copy each row into a character array first. Apply flips to the copy, then rebuild strings. Return the original board object if the move is invalid or the target cell is occupied.
How do I prepare for this in 48 hours?+
Practice grid direction loops and simulation problems with bounds checks. Write this one from scratch once, including the invalid-move cases from the examples. Focus on clean helper functions rather than memorizing, since the logic is simple once structured.