Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started
BFS Implementation
00:00
5 left

BFS Implementation

EasyPython

Problem

The Nio Robotics navigation stack represents reachable rover locations as a directed graph. Given an adjacency-list graph and a starting location, implement breadth-first search (BFS) and return the order in which locations are visited.

Visit each reachable location at most once. When processing a location, examine its neighbors in the order listed in the adjacency list. If multiple locations are discovered at the same BFS distance, preserve the discovery order created by that neighbor ordering. Ignore locations that are not reachable from start.

Formal Specification

Implement bfs_traversal(graph, start).

  • graph is a dictionary mapping a node identifier to a list of neighboring node identifiers.
  • start is a node identifier present in graph.
  • Return a list containing the BFS visitation order.
  • The graph may contain cycles and self-loops.
  • The graph is directed. An edge exists from node u to every node in graph[u].

Constraints

  • 1 <= number of nodes <= 10^5
  • 0 <= number of edges <= 2 * 10^5
  • Node identifiers are hashable and unique
  • Every neighbor identifier appears as a key in graph
  • The graph may contain cycles, self-loops, and disconnected components

Function Signature

def bfs_traversal(graph, start):
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements are in the Question tab.

You need to log in / sign up to run or submit.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.