Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Traverse Nested API Response Graph

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

Your question is Traverse Nested API Response Graph. 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 a starting endpoint ID start_id and a mapping api_map where each endpoint returns a JSON-like object with data and children, collect all data values reachable from start_id. Each children list contains IDs of other endpoints to visit. Return the collected data values in breadth-first traversal order, visiting each endpoint at most once even if multiple parents reference it.

Constraints

  • 1 <= len(api_map) <= 10^5
  • Each endpoint ID is a string
  • Each endpoint value contains data and children
  • Cycles may exist in the graph
  • A child endpoint may be referenced by multiple parents
  • Some child IDs may be missing from api_map

Function Signature

def collect_api_data(start_id, api_map):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output