The "Check if Move is Legal interview question" is a simulation of a move in an 8x8 board game like Othello or Reversi. You are given a grid, a starting position , and a color (Black or White). A move is "legal" if it completes a "good line." A good line is a sequence of at least 3 cells starting at that begins and ends with the player's color, with the opposite color in between.
Amazon ask the "Check if Move is Legal coding problem" to test a candidate's ability to handle multi-directional traversals and boundary conditions. It evaluations your proficiency with "Matrix interview pattern" logic and your ability to implement a well-defined set of rules accurately.
This problem follows the Directional Enumeration and Simulation pattern.
[(-1,-1), (-1,0), (-1,1), (0,-1), (0,1), (1,-1), (1,0), (1,1)].Move White to (3, 3).
When a problem involves directions (up, down, diagonals), always use a 2D array of offsets (e.g., dirs = [[0,1], [0,-1]...]). This makes your code much cleaner and less error-prone than writing 8 separate if blocks.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Check if Word Can Be Placed In Crossword | Medium | Solve | |
| Find the Minimum Area to Cover All Ones II | Hard | Solve | |
| Collecting Chocolates | Medium | Solve | |
| Valid Tic-Tac-Toe State | Medium | Solve | |
| Find the Minimum Area to Cover All Ones I | Medium | Solve |