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
Gloves Pair Selection Math
00:00
5 left

Gloves Pair Selection Math

EasyPython

Problem

An IFS Cloud warehouse stores gloves in several colors. Gloves are picked one at a time in complete darkness, and the picking order is unknown. Given the available quantity for each color, calculate the minimum number of gloves that must be picked to guarantee at least one matching pair of the same color.

The result must be guaranteed for the worst possible picking order. A pair consists of two gloves with the same color. You do not need to return the colors picked or simulate a particular order.

Formal Specification

Implement gloves_to_guarantee_pair(glove_counts), where glove_counts is a dictionary mapping a color name to its non-negative number of gloves. Return an integer representing the minimum number of picks that guarantees a matching pair. The input is guaranteed to contain enough gloves for a pair.

Constraints

  • 1 <= len(glove_counts) <= 10^5
  • 0 <= glove_counts[color] <= 10^9
  • At least one color has a quantity of at least 2
  • Color names are strings
  • The input contains enough gloves to guarantee a pair

Function Signature

def gloves_to_guarantee_pair(glove_counts):
Interviewer

Your question is Gloves Pair Selection Math. 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.