Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
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
Restriction Rule Engine for Shopping Basket
00:00
5 left

Restriction Rule Engine for Shopping Basket

MediumPython

Problem

Write a restriction rule engine for a shopping basket (bulk-buy limits per product and per category), returning MET/BREACHED.

Asked in the Coding round stage. Candidate linked LeetCode 3227767 Round 1 as the question asked.

Implement a function that checks whether a basket satisfies all bulk-buy limits.

Function contract

def check_basket_restrictions(basket, product_limits, category_limits):

  • basket is a list of items, where each item is a dict with keys product, category, and quantity.
  • product_limits maps product name to the maximum allowed total quantity.
  • category_limits maps category name to the maximum allowed total quantity.
  • Return the string "MET" if every limit is respected, otherwise return "BREACHED".

Examples

Example 1 basket = [{"product": "milk", "category": "dairy", "quantity": 2}, {"product": "bread", "category": "bakery", "quantity": 1}] product_limits = {"milk": 2, "bread": 2} category_limits = {"dairy": 3, "bakery": 2} Output: "MET"

Example 2 basket = [{"product": "eggs", "category": "dairy", "quantity": 4}, {"product": "yogurt", "category": "dairy", "quantity": 1}] product_limits = {"eggs": 4, "yogurt": 2} category_limits = {"dairy": 4} Output: "BREACHED"

Constraints

  • 1 <= len(basket) <= 10^4
  • 1 <= quantity <= 10^9
  • Every product and category in basket appears in the corresponding limits map
  • All limits are positive integers

Constraints

  • 1 <= len(basket) <= 10^4
  • 1 <= quantity <= 10^9
  • Every product and category in basket appears in the corresponding limits map
  • All limits are positive integers

Function Signature

def check_basket_restrictions(basket, product_limits, category_limits):
Interviewer

Your question is Restriction Rule Engine for Shopping Basket. 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.