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
Start free
Requesting Unique Pairs Repeatedly
00:00
5 left

Requesting Unique Pairs Repeatedly

MediumPython

Problem

Make sure that you can request the list of pairs in problem 1) multiple times without ever getting duplicate pairs

Asked in the first round, CoderPad stage. Part 2 builds on part 1: each call receives employee availability and previously returned pairs. If Robert is matched with Susy, Susy must not also be matched with someone else in the same call.

Implement next_pair_list(availability, used_pairs). availability is a dictionary mapping employee names to possible partners. Return a maximum-size list of unique, unordered pairs that does not contain any pair in used_pairs. Each employee may appear at most once in the returned list. Return [] when no unused pair is available. Break equal-size solutions lexicographically.

Input and Output

Use employee names as strings. Return pairs as two-element lists, sorted within each pair and ordered lexicographically.

Constraints

  • 1 <= number of employees <= 12
  • Employee names are unique strings
  • Each partner name appears as an employee in availability
  • An employee cannot be paired with themself
  • used_pairs contains canonical or non-canonical two-element pairs
  • Pairs in the result must be unique and disjoint

Function Signature

def next_pair_list(availability, used_pairs):
Interviewer

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

Sign up free to run or submit. Log in
Code
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 2
Run your code to see test output here.