Your question is Detect Circular Dependencies. 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.
IDFC FIRST Bank operates microservices whose dependencies form a directed graph. Given each service and the services it calls, detect whether any circular dependency exists and return one cycle if found.
Implement detect_circular_dependencies(dependencies), where dependencies is a dictionary mapping a service name to a list of services it directly depends on. Return a list of service names representing any directed cycle, without repeating the first service. Return an empty list when the dependency graph is acyclic.
All service names are non-empty strings. A dependency may appear only in a list and should still be treated as a graph vertex with no outgoing dependencies. The order of a valid cycle is not important, and any one cycle is acceptable.
def detect_circular_dependencies(dependencies):