Skip to content

Practice Knight Dialer

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#935
LeetCode Problem

Knight Dialer

Problem Statement

Use the phone keypad with rows 1 2 3, then 4 5 6, then 7 8 9, and finally 0 below 8. A chess knight moves two cells in one axis and one in the other, and may land only on digit cells. Start on any digit and make n - 1 valid jumps, recording the starting digit and each landing digit. Return the number of distinct length-n digit strings modulo 10^9 + 7.

Source: Knight Dialer on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 1
Output
10

# Example 2

Input
n = 2
Output
20

# Example 3

Input
n = 3131
Output
136006598

Constraints

1 <= n <= 5000

Related LeetCode Problems

Practice more problems similar to Knight Dialer.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.