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
Label Combinations With Constraints
00:00
5 left

Label Combinations With Constraints

HardPython

Problem

Implement an algorithm to find all possible combinations of a given set of email labels that can be applied to a message based on a set of constraint rules.

Implement find_label_combinations(labels, rules). Each rule is a dictionary with type requires, excludes, at_least_one, at_most_one, or exactly_one. Return every valid combination as a list of labels, with combinations and the outer result sorted lexicographically.

Input: unique label strings and valid rule dictionaries. Output: all satisfying combinations, including [] when valid.

Constraints

  • 1 <= len(labels) <= 20
  • Labels are unique strings.
  • Every rule references labels from labels.
  • requires rules contain one label and a list of required labels.
  • excludes, at_least_one, at_most_one, and exactly_one rules contain a nonempty labels list.
  • Return every valid combination, including the empty combination when it satisfies all rules.

Function Signature

def find_label_combinations(labels, rules):
Interviewer

Your question is Label Combinations With Constraints. 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.