Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Shortest Dependency Path in Microservices

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

Your question is Shortest Dependency Path in Microservices. 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

In an SAP BTP microservices landscape, each service may call one or more other services. Given a directed dependency graph, find the shortest dependency path from a source service to a target service.

Return the path as a list of service names, including both endpoints. If the target cannot be reached, return an empty list. If multiple shortest paths exist, return any one of them.

Formal Specification

Implement shortest_dependency_path(dependencies, source, target), where dependencies is a dictionary mapping a service name to a list of services it directly calls. source and target are strings. Return a list of strings representing the shortest directed path.

A dependency listed in the graph is directed: an edge from A to B means A depends on or calls B. Services with no outgoing dependencies may be absent from the dictionary.

Constraints

  • The graph contains at most 10^5 services.
  • The graph contains at most 2 * 10^5 directed dependencies.
  • Service names are non-empty strings.
  • The graph may contain cycles and disconnected components.
  • Multiple shortest paths may exist, and any one is valid.

Function Signature

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