Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Available Captures for Rook

XPChallenge Points: 10
levelLevel: Easy

You are given an 8×8 chessboard, where:
• 'R' → white rook (exactly one)
• 'B' → white bishop
• 'p' → black pawn
• '.' → empty square
The rook can move horizontally or vertically any number of squares until:
• It hits another piece, or
• It reaches the edge of the board.
A rook can capture a pawn 'p' if it can move to that pawn’s square in one move without any other piece blocking the way.
Your task is to return the number of pawns that the rook can capture.

Example 1:

Input: board = [ [".",".",".",".",".",".",".","."], [".","p","p","p","p","p",".","."], [".","p","p","B","p","p",".","."], [".","p","B","R","B","p",".","."], [".","p","p","B","p","p",".","."], [".","p","p","p","p","p",".","."], [".",".",".",".",".",".",".","."], [".",".",".",".",".",".",".","."] ]

Output: 0

Example 2:

Input: board = [ [".",".",".",".",".",".",".","."], [".",".",".","p",".",".",".","."], [".",".",".","R",".",".",".","p"], [".",".",".",".",".",".",".","."], [".",".",".",".",".",".",".","."], [".",".",".","p",".",".",".","."], [".",".",".",".",".",".",".","."], [".",".",".",".",".",".",".","."] ]

Output: 3

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result