Follow the Knight
MediumP3Coding
A knight stands on square (i, j) of a 10 x 10 chessboard, where (1, 1) is the top-left corner and (10, 10) the bottom-right. It must make exactly n moves, each a legal knight move that stays on the board (it may revisit squares).
Return the number of different squares where the knight can finish. With n = 0 the knight has not moved, so the answer is 1.
Example 1
- Input
- i = 1, j = 1, n = 1
- Output
- 2
- Why
- From a corner only two moves stay on the board.
Example 2
- Input
- i = 5, j = 5, n = 1
- Output
- 8
- Why
- From the middle all 8 knight moves are available.
Example 3
- Input
- i = 1, j = 1, n = 0
- Output
- 1
Constraints
- 1 <= i, j <= 10
- 0 <= n <= 1000
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 10. ⌘Enter runs, ⌘⇧Enter submits.