Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Lottery Coupons or Coin Change

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Lottery Coupons or Coin Change. Start with the requirements on the right.

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.

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):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output