0
Leetcode Problem 999. Available Captures for Rook
999. Available Captures for Rook
AI Mock Interview
Leetcode Solutions
Find and Check Rook's Attack Lines
Solution Idea
Algorithm Steps
Code Implementation
Complexity Analysis
Iterate over the chessboard to find the position of the white rook ('R').
Once the rook is found, store its position (row and column indices).
Check each of the four cardinal directions from the rook's position:
Move north (upward) by decrementing the row index until an obstacle is encountered or the edge is reached.
Move east (rightward) by incrementing the column index.
Move south (downward) by incrementing the row index.
Move west (leftward) by decrementing the column index.
In each direction, if a black pawn ('p') is encountered, increment the capture count.
If a white bishop ('B') is encountered or the edge of the board is reached, stop checking that direction.
Return the total capture count.
Iterative Search for Rook and Directional Pawn Check
Ask Question
Programming Language
Purpose:
General Question
Debug My Code
image/screenshot of info
(optional)
[+]
Full Screen
Loading...
Get Answer
Suggested Answer
Answer
Full Screen
Copy Answer Code
Loading...