Practice Knight Probability in Chessboard
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
On an n x n chessboard, a knight starts at the cell (row, column) and attempts to make exactly k moves. The rows and columns are 0-indexed, so the top-left cell is (0, 0), and the bottom-right cell is (n - 1, n - 1). A chess knight has eight possible moves it can make, as illustrated below. Each move is two cells in a cardinal direction, then one cell in an orthogonal direction. Each time the knight is to move, it chooses one of eight possible moves uniformly at random (even if the piece would go off the chessboard) and moves there. The knight continues moving until it has made exactly k moves or has moved off the chessboard. Return the probability that the knight remains on the board after it has stopped moving.
Source: Knight Probability in Chessboard on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
n = 3, k = 2, row = 0, column = 0
0.06250
# Example 2
n = 1, k = 0, row = 0, column = 0
1.00000
Constraints
Related LeetCode Problems
Practice more problems similar to Knight Probability in Chessboard.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.