Gift Token Combinations

Dynamic Programming Dp Coin Change Combinations

Problem Description

In celebration of Epiphany, a holiday known for the exchange of gifts, imagine you have a set of gift tokens with different values. Your task is to find out how many different combinations of these tokens can sum up to a given target value. You have an infinite supply of each token.

Details

  • You are given an array of positive integers tokens, where each integer represents the value of a gift token.
  • You are also given a positive integer target which is the total value you need to achieve using combinations of tokens.
  • Write a function that returns the number of unique combinations that add up to the target value. Two combinations are considered unique if they have a different count of at least one type of token.

Example

For instance, if tokens = [1, 2, 3] and target = 4, some possible combinations are:

  • 1 + 1 + 1 + 1
  • 1 + 1 + 2
  • 1 + 3
  • 2 + 2

Thus, the function should return 4.

Notes

  • Combinations are considered regardless of the order of tokens (i.e., 1 + 3 is the same as 3 + 1).
  • Aim for a dynamic programming solution to efficiently solve the problem.

Happy coding, and enjoy the spirit of gift-giving this Epiphany!


Starter Code

Below is some starter code in multiple languages. Complete the function to solve the problem.