Imagine you're a cashier with an unlimited supply of different coin denominations, and you need to find out how many different ways you can make change for a specific amount. This is exactly what the Combination Sum IV problem asks!
Given an array of distinct positive integers nums and a target integer target, return the number of possible combinations that add up to the target. Unlike traditional combination problems, order matters here - so [1,2] and [2,1] are considered different combinations.
Example: If nums = [1,2,3] and target = 4, the valid combinations are: [1,1,1,1], [1,1,2], [1,2,1], [2,1,1], [2,2], [1,3], [3,1] - that's 7 different ways!
The challenge is to count all these combinations efficiently without actually generating them, as the number can be very large.
Input & Output
Constraints
- 1 โค nums.length โค 200
- 1 โค nums[i] โค 1000
- All elements of nums are unique
- 1 โค target โค 1000
- The number of possible combinations that add up to target is guaranteed to fit in a 32-bit integer