Problem
Small Business Network: Degrees of Separation
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.
Examples
01 · 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.
02 · 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 problems
- Set Total Palindrome Transformation CostSeen Feb 2026
- Smart Gardener (Intuit India)Seen Feb 2024
- Jumping Kady (Intuit India)Seen Feb 2024
- Longest Cipher (Intuit India)Seen Feb 2024
- Maximum Reward (Intuit India)Seen Feb 2024
- Spreading Fire (Intuit India)Seen Feb 2024
- Virus Spread (Intuit India)Seen Feb 2024
- Ice Cream SticksSeen Feb 2024
public String[] shortestBusinessPath(String[][] relationships, String source, String target) {
// write your code here
}relationships[["A", "B"], ["B", "C"]]
source"A"
target"C"
expected["A", "B", "C"]
sign in to submit