Imagine you're a cashier at a vintage arcade where coins have unusual denominations! You have access to:
- Unlimited coins of values
1,2, and6 - Only 2 coins of value
4
Given a target sum n, your task is to determine how many different ways you can make change to reach exactly that amount.
Important: The order of coins doesn't matter - using coins [2, 2, 6] is considered the same as [2, 6, 2].
Since the number of ways can be astronomically large, return your answer modulo 109 + 7.
Example: For n = 4, you could make it with: [4], [2, 2], [1, 1, 1, 1], [1, 1, 2] - that's 4 different ways!
Input & Output
Visualization
Time & Space Complexity
Single pass through the DP array for each coin type, total time is proportional to n times number of coin types
DP array of size n+1 to store the number of ways for each sum
Constraints
- 1 โค n โค 104
- You have unlimited coins of values 1, 2, and 6
- You have exactly 2 coins of value 4
- Return answer modulo 109 + 7