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
Earliest Full Connectivity
00:00
5 left

Earliest Full Connectivity

HardPython

Problem

Given a log of lines ' A became friend to B', return the earliest timestamp at which everyone is connected (friends transitively).

Asked in the Coding round 1 stage. Implement earliest_connected_timestamp(logs). Each log line is a string such as "12 Alice became friend to Bob"; timestamps are integers, and the log may not be ordered. Consider every person appearing in the logs. Return -1 if all people never become connected.

Examples: ['1 A became friend to B', '3 B became friend to C'] returns 3; ['5 A became friend to B', '2 B became friend to C'] returns 5 after timestamp ordering.

Constraints: There can be zero or more lines, each line has the stated format, and the two people on a line are distinct.

Constraints

  • 0 <= len(logs) <= 10^5
  • Each line has the format '<integer timestamp> A became friend to B'
  • Each timestamp fits in a signed 32-bit integer
  • The two people on each line are distinct
  • A person is identified by a nonempty token without whitespace
  • Return -1 when all people never become connected

Function Signature

def earliest_connected_timestamp(logs):
Interviewer

Your question is Earliest Full Connectivity. 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.