Find degrees of connection in a LinkedIn graph
Company: Liftoff
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Quick Answer: This question evaluates understanding of graph traversal, reachability and shortest-path concepts along with the ability to manage performance constraints on large sparse graphs.
Constraints
- 0 <= src,dst < n
Examples
Input: (5, [(0, 1), (1, 2), (0, 3), (3, 4)], 0, 2, False)
Expected Output: 2
Explanation: Two hops.
Input: (3, [], 1, 1, True)
Expected Output: (0, [1])
Explanation: Source equals destination.
Input: (4, [(0, 1)], 0, 3, False)
Expected Output: -1
Explanation: Unreachable.
Input: (4, [(0, 1), (1, 2), (0, 2)], 0, 2, True)
Expected Output: (1, [0, 2])
Explanation: Direct shortest path.
Hints
- BFS in an unweighted graph finds minimum degree distance.