FastPrepApply a Reversi Move
Problems/Apply a Reversi Move

Apply a Reversi Move

Amazon logoAmazon● MediumFULLTIMEOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report describes one Reversi move with eight-direction capture and an unchanged-board result for an invalid move. The judged core matches the visible source at about 90%.

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 = 1col = 3player = "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 = 2col = 2player = "B"return = ["..B..","..B..","BBBBB","..B..","..B.."]

The move captures one white piece in each cardinal direction.

Example 3

board = ["...","...","..."]row = 1col = 1player = "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.

More Amazon problems

  • Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
See Amazon hiring insights
Saved
class Solution {
    public String[] applyReversiMove(String[] board, int row, int col, char player) {
        // Write your code here.
    }

}
Checking account…