FastPrepKnight Dialer Sequences
Problems/Knight Dialer Sequences

Knight Dialer Sequences

WhatNot logoWhatNot● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in two phone screens for experienced engineers at Whatnot, in mid 2026 and again that fall. The second report says its question was the same one as the first. A knight jumps around a phone keypad, and the task is to count the numbers it can dial from a given key in a given number of jumps.

Neither report gives limits. Here, there are at most 40 jumps, so the count fits in a 64-bit integer and no remainder is needed.

Our version is about 95% the same as the reported question.

A chess knight stands on a phone keypad laid out like this:

1 2 3
4 5 6
7 8 9
  0  

The knight begins on the key startDigit, which counts as pressed. It then makes exactly hops moves. Each move is a normal knight move: two keys in one direction (up, down, left or right) and one key to the side. A move must land on a digit key. The empty spots to the left and right of 0 are not keys. Each landing presses that key.

Return how many distinct digit sequences the knight can dial. Each sequence has hops + 1 digits and starts with startDigit. The knight may land on the same key more than once.

Function

countDialedNumbers(startDigit: int, hops: int) → long

Examples

Example 1

startDigit = 1hops = 1return = 2

From 1, the knight can only land on 6 or 8. The two sequences are 16 and 18.

Example 2

startDigit = 4hops = 2return = 6

From 4, the first hop lands on 3, 9 or 0. Each of those has two next keys: 3 goes to 4 or 8, 9 goes to 2 or 4, and 0 goes to 4 or 6. That gives 3 * 2 = 6 sequences.

Example 3

startDigit = 5hops = 0return = 1

With no hops, the only sequence is the starting key 5 by itself.

Example 4

startDigit = 5hops = 3return = 0

No key is a knight move away from 5, so the knight cannot make even one hop. No sequence of the required length exists.

Constraints

  • 0 <= startDigit <= 9
  • 0 <= hops <= 40
  • The answer is less than 2^53, so it fits in a 64-bit integer.

More WhatNot Phone Screen questions

  • Adjacent Pair and Run RemovalPHONE SCREEN · Seen Nov 2026
  • Merge Sorted Squares of Two ArraysPHONE SCREEN · Seen Nov 2026
  • User Journey PathsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Reachable Exits in an Obstacle GridPHONE SCREEN · Seen Oct 2026
  • Palindrome with One DeletionPHONE SCREEN · Seen Oct 2026
  • Search a 2D MatrixPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Attraction Route Without Reusing TrailsPHONE SCREEN · Seen Sep 2026
  • Earliest Car for Each PassengerPHONE SCREEN · Seen Sep 2026
  • Minimum Stores for a Shopping ListPHONE SCREEN · Seen Sep 2026
  • User Journey Paths from a Log StreamPHONE SCREEN · Seen Jul 2026

Similar questions at other companies

  • All Halfway Courses Across Course TracksCrunchyroll · PHONE SCREENCrunchyroll interview questions
  • Minimum Total Layover WaitGoogle · PHONE SCREENGoogle interview questions
  • Shortest Paths in a Nonnegative Directed GraphNation with NaMo · PHONE SCREEN
  • Minimum Traveling Salesperson TourGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
  • Minimum Completion Time for DAG DependenciesAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Work Order Critical PathHadrian · PHONE SCREENHadrian interview questions
  • Longest Name Chain in a Directed Acyclic GraphOscar Health · PHONE SCREEN
  • Service Dependency Load FactorsRobinhood · PHONE SCREENRobinhood interview questions
  • Employee Hierarchy Cycle and Depth AnalysisMicrosoft · PHONE SCREENMicrosoft interview questions
  • Longest Chain BookingAirbnb · PHONE SCREENAirbnb interview questions

WhatNot interview experiences

  • Whatnot SWE New Grad Second Technical Interview: 8 Experiences
  • Whatnot interviews · October 2026
  • Whatnot Experienced SWE Phone Screen Questions: 2 Experiences
  • Whatnot SWE Interview Questions: 6 Experiences
All WhatNot interview questionsSee WhatNot hiring insights
Saved
class Solution {
    public long countDialedNumbers(int startDigit, int hops) {
        // write your code here
    }
}
Checking account…