The knight's adjacency map on the dial pad:
- , , , ,
- , , , ,
For n = 3, start with all s: [1,1,1,1,1,1,1,1,1,1]. After hop : digit gets contributions from and , so . Continue for all digits. After hop , sum all values for the answer.
You process digits per hop, with constant transitions per digit. That's time. With arrays of size , space is .