Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Shortest Professional Connection Path

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Shortest Professional Connection Path. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Given an undirected graph of professional connections, find the shortest path between two individuals. The input consists of connections, a list of pairs [a, b] representing mutual connections, and two strings start and target. Return the shortest path as a list of names from start to target, or an empty list if no path exists.

Constraints

  • 0 <= len(connections) <= 10^4
  • Each connection contains exactly two non-empty strings
  • The graph is undirected and may be disconnected
  • start and target are strings
  • Names are case-sensitive

Function Signature

def shortest_connection_path(connections, start, target):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output