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
Cycle Detection and Components
00:00
5 left

Cycle Detection and Components

MediumPython

Problem

Anduril autonomous vehicles exchange peer-to-peer status through an undirected network of vehicle links. Given all vehicle identifiers and active links, determine whether any cycle exists and return every connected component, including isolated vehicles.

Implement analyze_vehicle_network(vehicles, links).

Formal Specification

  • vehicles is a list of unique strings.
  • links is a list of two-element lists, where each pair [u, v] represents an undirected link between vehicles u and v.
  • Every endpoint in links appears in vehicles, and self-links are not present.
  • Return a dictionary with:
    • has_cycle: a boolean that is True if any component contains an undirected cycle.
    • components: a list of component objects. Each object has vehicles, a lexicographically sorted list of identifiers, and has_cycle, indicating whether that component contains a cycle.
  • Sort components by the first vehicle identifier in each component. Do not mutate the inputs.

A cycle exists when an edge connects two vehicles that are already connected by previously processed edges. Duplicate links are considered separate edges, so two identical links form a cycle under the standard undirected multigraph definition.

Constraints

  • 1 <= len(vehicles) <= 2 * 10^5
  • 0 <= len(links) <= 3 * 10^5
  • Vehicle identifiers are unique non-empty strings of length at most 32
  • Every link endpoint appears in vehicles
  • Self-links are not present
  • Duplicate links are allowed and count as separate edges

Function Signature

def analyze_vehicle_network(vehicles, links):
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.