Small Business Network: Degrees of Separation
Updated
Problem statement
QuickBooks stores business relationships between companies. Each relationship connects two businesses, and relationships should be treated as undirected graph edges.
Given the relationship list, a source business, and a target business, return one shortest relationship path from source to target. The path should include both endpoints.
If no relationship path exists, return an empty array. If source is the same as target, return an array containing only that business.
Function
shortestBusinessPath(relationships: String[][], source: String, target: String) → String[]Examples
Example 1
relationships = [["A", "B"], ["B", "C"]]source = "A"target = "C"return = ["A", "B", "C"]The relationships form A <--> B <--> C, so the shortest path from A to C goes through B.
Example 2
relationships = [["A", "B"], ["C", "D"]]source = "A"target = "D"return = []A and D are in different connected components, so there is no relationship path.
Constraints
- Each entry in
relationshipscontains exactly two business names. - Relationship edges are undirected.
- If multiple shortest paths exist, returning any one shortest path is acceptable.
More Intuit interview questions
- VIP and Regular Service SchedulerPHONE SCREEN · Seen Nov 2026
- Longest Uninterrupted Work BlockPHONE SCREEN · Seen Sep 2026
- VIP-Priority Fixed-Window Rate LimiterPHONE SCREEN · Seen Aug 2026
- Longest Common SubstringPHONE SCREEN · Seen May 2021
- Lowest Common Ancestor in a Rooted TreePHONE SCREEN · Seen Feb 2020
- Zero or One Parent Groups in a TreePHONE SCREEN · Seen Feb 2020
- Number of IslandsONSITE INTERVIEW · Seen Nov 2026
- Employee Promotion OpportunitiesOA · Seen Oct 2026
- Next Pascal Row CoefficientOA · Seen Oct 2026
- Parse Router LogsOA · Seen Oct 2026