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
Package Fitting Into Spaces
00:00
5 left

Package Fitting Into Spaces

EasyPython

Problem

Foundation Robotics Labs is calibrating a packing station with packages and available storage spaces. Each package has a size, and a package fits in a space when the package size is less than or equal to the space size. Each package and each space can be used at most once.

Given integer arrays packages and spaces, return the maximum number of packages that can be placed.

Formal Specification

Implement fit_packages(packages, spaces):

  • Input: packages, a list of positive integers, and spaces, a list of positive integers.
  • Output: an integer representing the largest number of packages that can be assigned to compatible spaces.
  • Packages and spaces may be reordered. The returned count is the only required output.

Constraints

  • 0 <= len(packages), len(spaces) <= 10^5
  • 1 <= packages[i], spaces[j] <= 10^9
  • Each package can be assigned to at most one space
  • Each space can hold at most one package

Function Signature

def fit_packages(packages, spaces):
Interviewer

Your question is Package Fitting Into Spaces. 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.