784. The Number of Ways to Make the Sum

Given an infinite number of coins with values 1, 2, and 6, and only 2 coins with value 4 and an integer n, return the number of ways to make the sum n using the available coins.

Since the result may be very large, return it modulo 109 + 7.

Example 1:

Input: n = 5  

Output: 4

Explanation:

Here are the valid combinations:

[1, 1, 1, 1, 1]

[1, 1, 1, 2]

[1, 2, 2]

[4,1]

Example 2:

Input: n = 10  

Output: 16

Explanation:

Some valid combinations include:

[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]

[2, 2, 2, 2, 2]

[6, 2, 2]

[4, 4, 2] (Valid since 4 can be used at most twice)

[6, 4]

[2, 2, 2, 2, 1, 1]

[1, 1, 1, 1, 6]

Now Your Turn!

Pick the correct output for the given input

Input: n = 7  

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 ≤ n ≤ 105

Fun Facts

0
class Solution {
public:
int numberOfWays(int n) {
}
};
Test Case

Input:

N