Knight Probability in Chessboard

Medium

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 = 0
Output:0.0625
Explanation:

1/16 probability.

Input:n = 1, k = 1, row = 0, column = 0
Output:0.0
Explanation:

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 = 2
Output:1.0
Explanation:

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

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!