Question bank › Backtracking
Dsa Backtracking Medium

Knight's Keypad

On a 3x3 numeric keypad (0-8 arranged in 3 rows), a 'Knight' move is the same as in chess (2 cells one way, 1 cell perpendicular). You must generate a sequence of moves of length L, starting from digit D. Constraint: You can visit each digit on the keypad at most 2 times. How many unique sequences exist? Keypad layout: 0 1 2 3 4 5 6 7 8 Input: Two integers, L and D. L is the number of digits in the sequence (including the start). Example: Input: 2 0 Output: 2 (Explanation: From 0, knight can move to 5 or 7. Sequences: [0,5], [0,7])

Key concepts

backtrackinggraph traversalstate tracking

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.