The Knight Dialer interview question is a combinatorial counting problem based on chess movements. A knight is placed on a standard phone keypad. From its current digit, it can jump to any digit reachable by a valid knight move. You need to find how many unique phone numbers of length can be dialed. The result should be returned modulo .
Companies like Meta, Amazon, and Google use the Knight Dialer coding problem to test a candidate's ability to implement Dynamic Programming. It evaluates whether you can model a problem as a state machine where the number of ways to reach a digit in steps depends on the number of ways to reach its "jump-source" neighbors in steps.
This problem follows the Linear Dynamic Programming (State Machine) pattern.
dp[k][digit] is the number of sequences of length k ending on digit.dp[k][digit] = sum(dp[k-1][neighbor]) for all neighbors that can jump to that digit.For :
This problem is a specific case of counting paths in a graph. For very large (), this can be solved in using Matrix Exponentiation. Mentioning this shows high-level mathematical and algorithmic depth.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Ways to Express an Integer as Sum of Powers | Medium | Solve | |
| Domino and Tromino Tiling | Medium | Solve | |
| Number of Dice Rolls With Target Sum | Medium | Solve | |
| Count Ways To Build Good Strings | Medium | Solve | |
| Champagne Tower | Medium | Solve |