The Knight Probability in Chessboard interview question asks for the probability that a knight remains on an board after random moves. In each step, the knight chooses one of its 8 legal moves with equal probability (1/8 each). If a move takes the knight off the board, it stays off forever.
Companies like Goldman Sachs and Google use the Knight Probability coding problem to test a candidate's understanding of Probability and DP. It evaluations whether you can distinguish between "counting paths" and "summing probabilities." It tests your ability to handle floating-point results and 3D state spaces.
This problem uses Dynamic Programming with a probability state.
dp[k][r][c] is the probability the knight is at after exactly k moves.dp[0][startRow][startCol] = 1.0. All other cells at step 0 are 0.0.board, start at (0,0), .
Practice "state reduction" in DP. For problems where the current time/step only depends on the immediately preceding one, you can always optimize space complexity by using only two copies of the base structure (current and previous). This is a vital Matrix interview pattern trick.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Count Ways To Build Good Strings | Medium | Solve | |
| Paint Fence | Medium | Solve | |
| Number of Dice Rolls With Target Sum | Medium | Solve | |
| Ways to Express an Integer as Sum of Powers | Medium | Solve | |
| Domino and Tromino Tiling | Medium | Solve |