Apply a Reversi Move
Problem statement
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.
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.
Unlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- 2 more worked examples, explained
- Guided hints and editorial
- Run your code on real test cases
$99 billed yearly — or $19 month-to-month. Cancel anytime.