Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
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
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Build my plan
All-Pairs Connection Formation Time
00:00
5 left

All-Pairs Connection Formation Time

MediumPython

Problem

Aurora Innovation models communication among members of an autonomous vehicle engineering team as timestamped acquaintance events. Given n people and a list of direct connections, determine the earliest time at which every person is connected to every other person through a direct or indirect path.

A connection is undirected. Events may be provided in any order, and multiple events may have the same timestamp. All events with the same timestamp are considered available simultaneously.

Formal Specification

Implement earliest_full_connectivity(n, connections).

  • n is an integer representing people labeled 0 through n - 1.
  • connections is a list of [timestamp, person_a, person_b] records.
  • Return the earliest timestamp at which the graph is connected.
  • Return -1 if the graph never becomes fully connected.
  • A person is always considered connected to themself.

Constraints

  • 1 <= n <= 2 * 10^5
  • 0 <= len(connections) <= 2 * 10^5
  • 0 <= timestamp <= 10^9
  • 0 <= person_a, person_b < n
  • person_a != person_b
  • Duplicate connections may appear.
  • The input list is not necessarily sorted by timestamp.

Function Signature

def earliest_full_connectivity(n, connections):
Interviewer

Your question is All-Pairs Connection Formation Time. Start with the requirements in the Question tab.

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.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.