Tap here to switch tabs
Problem
Submissions

Problem: Available Captures for Rook

med
30 min
Try to solve the Available Captures for Rook problem.

Statement

You are given an 8imes88 imes 8 matrix board representing a chessboard containing empty squares and chess pieces:

  • Exactly 11 white rook denoted by 'R'

  • Zero or more white bishops denoted by 'B'

  • Zero or more black pawns denoted by 'p'

  • Empty squares denoted by '.'

A rook can move any number of squares horizontally or vertically across four directions (up, down, left, and right) until it reaches the edge of the board or another piece:

  • If the rook encounters a black pawn 'p', it can capture that pawn, and movement in that direction terminates.

  • If the rook encounters a white bishop 'B', its movement is blocked, and it cannot capture any piece further in that direction.

Return the total number of pawns the rook can capture.

Constraints:

  • board.length =8= 8

  • board[i].length =8= 8

  • board[i][j] is either 'R', '.', 'B', or 'p'

  • There is exactly 11 cell where board[i][j] == 'R'

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Available Captures for Rook

med
30 min
Try to solve the Available Captures for Rook problem.

Statement

You are given an 8imes88 imes 8 matrix board representing a chessboard containing empty squares and chess pieces:

  • Exactly 11 white rook denoted by 'R'

  • Zero or more white bishops denoted by 'B'

  • Zero or more black pawns denoted by 'p'

  • Empty squares denoted by '.'

A rook can move any number of squares horizontally or vertically across four directions (up, down, left, and right) until it reaches the edge of the board or another piece:

  • If the rook encounters a black pawn 'p', it can capture that pawn, and movement in that direction terminates.

  • If the rook encounters a white bishop 'B', its movement is blocked, and it cannot capture any piece further in that direction.

Return the total number of pawns the rook can capture.

Constraints:

  • board.length =8= 8

  • board[i].length =8= 8

  • board[i][j] is either 'R', '.', 'B', or 'p'

  • There is exactly 11 cell where board[i][j] == 'R'