FastPrepShortest Path Through Numbers Sharing a Digit
Problems/Shortest Path Through Numbers Sharing a Digit

Shortest Path Through Numbers Sharing a Digit

Google logoGoogle● MediumNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report starts with a rule for whether two numbers share a digit. It then gives the exact path example [1,20,40,41]. Here we ask for the lexicographically smallest shortest path, and we set how zero is treated. Our version is about 88% the same as the reported question.

You are given an array of distinct non-negative integers numbers and two values start and end that appear in the array.

You can move directly between two values when they share at least one digit in their ordinary decimal representations. Find a path from start to end using these moves.

Return a path with the minimum number of edges. Among several shortest paths, return the lexicographically smallest value sequence. Return an empty array when no path exists. The decimal representation of zero contains digit 0.

Function

shortestCommonDigitPath(numbers: int[], start: int, end: int) → int[]

Examples

Example 1

numbers = [1,20,40,41]start = 1end = 20return = [1,41,40,20]

Each consecutive pair shares digit 1, 4, and 0 respectively.

Example 2

numbers = [12,23,34,45]start = 12end = 45return = [12,23,34,45]

The chain shares digits 2, 3, and 4.

Example 3

numbers = [10,22,35]start = 10end = 35return = []

No pair in the array shares a digit.

Constraints

  • 1 <= numbers.length <= 200000.
  • 0 <= numbers[i] <= 10^9, and all values are distinct.
  • start and end appear in numbers.

More Google Phone Screen questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
  • Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
  • Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
  • Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Linked Merchants Within Two HopsStripe · PHONE SCREENStripe interview questions
  • Bus RoutesBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Jump Game IVZomato / Eternal · ONSITE INTERVIEWZomato / Eternal interview questions
  • Largest Island After One FlipOracle · ONSITE INTERVIEWOracle interview questions
  • Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Shortest Pin Path Through TopicsPinterest · PHONE SCREENPinterest interview questions
  • Currency Conversion RateAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Route Graph Reachability with a Broken LinkFigma · PHONE SCREENFigma interview questions
  • Minimum Currency ConversionsEPAM · PHONE SCREENEPAM interview questions
  • Finite Web CrawlerMongoDB · PHONE SCREEN · ONSITE INTERVIEWMongoDB interview questions

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int[] shortestCommonDigitPath(int[] numbers, int start, int end) {
        // Write your code here.
    }
}
Checking account…