Loading problem...
You are given an integer array denominations representing currency units of distinct face values, and an integer targetValue representing a total monetary amount you wish to assemble.
Your task is to determine how many unique ways you can combine these currency units to reach exactly the target amount. Each denomination can be used an unlimited number of times in any combination.
Key Characteristics:
The result is guaranteed to fit within a signed 32-bit integer.
targetValue = 5
denominations = [1,2,5]4There are four distinct ways to assemble the value 5: • 5 = 5 (using one 5-unit) • 5 = 2 + 2 + 1 (using two 2-units and one 1-unit) • 5 = 2 + 1 + 1 + 1 (using one 2-unit and three 1-units) • 5 = 1 + 1 + 1 + 1 + 1 (using five 1-units)
targetValue = 3
denominations = [2]0The only available denomination is 2. Since 3 is odd and we can only add multiples of 2, it is impossible to reach exactly 3. Therefore, there are zero valid combinations.
targetValue = 10
denominations = [10]1With only a 10-unit denomination available, the only way to reach exactly 10 is to use one 10-unit. Hence, there is exactly one valid combination.
Constraints