Description
Given an n x n chessboard, a knight starts at (row, column) and makes k moves. Return probability it remains on board.
Examples
Input:
n = 3, k = 2, row = 0, column = 0Output:
0.0625Explanation:
1/16 probability.
Input:
n = 1, k = 1, row = 0, column = 0Output:
0.0Explanation:
On a 1x1 board, the knight has no valid moves from any position. After 1 move, the knight must leave the board, so the probability of staying on the board is 0.
Input:
n = 4, k = 1, row = 2, column = 2Output:
1.0Explanation:
From position (2,2) on a 4x4 board, all 8 possible knight moves land on valid squares within the board boundaries. Since every move keeps the knight on the board, the probability is 8/8 = 1.0.
Constraints
- •
1 ≤ n ≤ 25