FastPrepShortest Path from Encoded Graph Edges
Problems/Shortest Path from Encoded Graph Edges

Shortest Path from Encoded Graph Edges

BitGo logoBitGo● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a BitGo full-time online assessment. The report leaves out how the edges are encoded, whether the graph has direction, the exact form of the return value, and the result when a node cannot be reached. We chose those. The task is parsing plus BFS. Our version is about 82% the same as the reported question.

You are given an array edges describing an unweighted, undirected graph. Each entry has the exact form "u,v", where u and v are nonnegative decimal node labels.

Parse the edges and return the minimum number of edges on any path from source to target.

  • Duplicate edges and self-loops may appear and do not change the answer.
  • When source equals target, return 0.
  • When target is unreachable, return -1.

Function

shortestHopDistance(edges: String[], source: int, target: int) → int

Examples

Example 1

edges = ["0,1","1,2","0,3","3,2"]source = 0target = 2return = 2

Both 0 → 1 → 2 and 0 → 3 → 2 use two edges, so the shortest-hop distance is 2.

Example 2

edges = ["10,11","12,13"]source = 10target = 13return = -1

The source and target belong to different connected components.

Constraints

  • 0 <= edges.length <= 200000.
  • Every edge is exactly two decimal integers separated by one comma, with no spaces.
  • Every node label, source, and target is between 0 and 1000000000.

More BitGo Online Assessment questions

  • First Fibonacci Number at Least the Array SumOA · Seen Nov 2025

Similar questions at other companies

  • Find Minimum City HopsAmazon · OA
  • Linked Merchants Within Two HopsStripe · PHONE SCREENStripe interview questions
  • Word LadderGoogle · ONSITE INTERVIEWGoogle interview questions
  • Find Duplicate Files in a FilesystemHarvey · PHONE SCREEN · ONSITE INTERVIEWHarvey interview questions
  • Shortest Word Transformation SequenceReddit · PHONE SCREENReddit interview questions
  • Word LadderGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
  • Word LadderMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Word Ladder IIBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Race a Friend to a Shared HomeIntuit · OAIntuit interview questions
  • Shortest Route Through a Traced MazeDuolingo · OADuolingo interview questions
All BitGo interview questionsSee BitGo hiring insights
Saved
class Solution {
    public int shortestHopDistance(String[] edges, int source, int target) {
        // Write your code here.
    }
}
Checking account…