The Available Captures for Rook interview question is a grid-based simulation problem. You are given an 8x8 chessboard with one white rook ('R'), several white bishops ('B'), some black pawns ('p'), and empty squares ('.'). A rook moves horizontally or vertically. It can capture a pawn if it reaches it without hitting a bishop or the edge of the board first. Your task is to count how many pawns the rook can capture. This Available Captures for Rook coding problem is about directional traversal in a matrix.
Companies like Square and Google use this to test basic matrix navigation skills. It evaluates if a candidate can correctly implement "straight-line" movement in four directions while handling blocking conditions. It's an excellent way to check for clean code and effective use of loop control (like break).
This follows the Array, Matrix, Simulation interview pattern.
Imagine the rook is at (4, 4).
For matrix problems involving directional movement, define a directions array like [[0,1], [0,-1], [1,0], [-1,0]]. This allows you to use a single loop to handle all four directions, making your code cleaner and less prone to repetition errors.