bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 999. Available Captures for Rook

999. Available Captures for Rook

Leetcode Solutions

Find and Check Rook's Attack Lines

  1. Iterate over the chessboard to find the position of the white rook ('R').
  2. Once the rook is found, store its position (row and column indices).
  3. 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.
  4. In each direction, if a black pawn ('p') is encountered, increment the capture count.
  5. If a white bishop ('B') is encountered or the edge of the board is reached, stop checking that direction.
  6. Return the total capture count.
UML Thumbnail

Iterative Search for Rook and Directional Pawn Check

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...