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
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
Get started
Lottery Coupons or Coin Change
00:00
5 left

Lottery Coupons or Coin Change

MediumPython

Problem

TraceLink Product Track may evaluate rule sets containing reusable numeric values. Given a collection of coin or coupon denominations and a target value, return every unique combination whose values sum to the target.

Each denomination may be selected unlimited times. The input may contain duplicate denomination values, but duplicate combinations must appear only once. Within every combination, values must be in nondecreasing order. Return the combinations in lexicographic order, where the first differing value determines ordering. Return an empty list when no combination exists.

Formal Specification

Implement find_combinations(denominations, target).

  • denominations is a list of positive integers.
  • target is a positive integer.
  • Return a list of lists of integers.
  • Each returned list must sum to target.
  • The same denomination can be used repeatedly.
  • A combination's ordering does not matter mathematically, so [2, 3] and [3, 2] are the same combination.

Constraints

  • 1 <= len(denominations) <= 20
  • 1 <= denominations[i] <= 100
  • Duplicate denomination values may occur
  • 1 <= target <= 300
  • Every denomination is positive

Function Signature

def find_combinations(denominations, target):
Interviewer

Your question is Lottery Coupons or Coin Change. 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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.