Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Service Dependency Graph Traversal

Medium
CodingSearchingtraversalDependenciesGraphsAsked 1 times

Problem

Given a directed graph of service dependencies represented as a dictionary graph, where each key is a service name and its value is a list of dependent services, implement a traversal starting from start_service. Return the services visited in traversal order using either breadth-first search (BFS) or depth-first search (DFS), based on a method parameter equal to "bfs" or "dfs". If a service appears multiple times through different paths, visit it only once.

Constraints

  • 1 <= number of services <= 10^5
  • 0 <= total dependencies <= 2 * 10^5
  • Service names are non-empty strings
  • method is either "bfs" or "dfs"

Function Signature

def traverse_dependencies(graph, start_service, method):
Practicing as: Solutions Architect interview at NiCE

Hi, I'll play your NiCE interviewer for the Solutions Architect role. Candidates describe these interviews as mixed and moderately difficult, so expect me to be professional and fair. Take your time with the question above and answer like we're in the room.

You are practicing as a guest. Sign up free to run your code against the sample data. Your draft stays right here.

Sign up freeI have an account
def solve(rows):
    counts = {}
    for row in rows:
        ...
    return result
Sign up to unlock solutions
NiCE Solutions Architect Interview QuestionsNiCE Interview Questions
Next questions
Graph Traversal with BFS and DFSEasyMetaBFS for System Dependency GraphMediumDepth-First Traversal of GraphEasy