X

DAYS

:

HOUR

:

MINS

:

SEC

Copied to Clipboard
Count ways to express N as the sum of 1,3 and 4
Easy Accuracy: 40.25% Submissions: 1016 Points: 2

Given N, count the number of ways to express N as sum of 1, 3 and 4 modulo (109+7).

Example 1:

Input:
N = 1
Output:
1
Explanation:
There is only one way to represent 1 as
sum of 1,3 and 4. 1 = {1}.


Example 2:

Input:
N = 3
Output:
2
Explanation:
There is 2 ways to represent 3 as sum
of 1,3 and 4. 3 = {1,1,1}, and 3 = {3}.

You don't need to read input or print anything. Your task is to complete the function countWays() which takes a Integer N as input and returns the number of ways possible.

Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)

Constraints:
1 <= N <= 105

We are replacing the old Disqus forum with the new Discussions section given below.