Holiday Gift Bundles

Dynamic Programming Holiday Combinations

Problem: Holiday Gift Bundles

Santa is preparing special gift bundles for children this holiday season. He has a list of different gift types, each with an associated "joy value". Santa wants to know in how many unique ways he can create a bundle of gifts such that the total joy exactly equals a given target value. Each gift type can be chosen an unlimited number of times. Order does not matter; for example, a bundle with gifts [2, 3, 3] is considered the same as [3, 2, 3].

Task

Write a function countGiftBundles(gifts, target) that calculates the number of unique combinations of gift selections that sum up exactly to the target joy value.

Input

  • An array/list of positive integers gifts representing the joy values of each gift type.
  • A positive integer target representing the desired total joy value.

Output

Return an integer indicating the number of unique combinations that sum up to the target joy.

Example

For example, if gifts = [2, 3, 5] and target = 8, some valid bundles (order ignored) might be:

  • [3, 5]
  • [2, 2, 2, 2]
  • [2, 3, 3]

Your function should return the total count of valid combinations.

Hint

Consider using dynamic programming to build up the solution by solving smaller subproblems for each possible joy value up to the target.

Happy coding and enjoy the holiday season!