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}.

 

Your Task:
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.
Click here to view old Disqus comments.


to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Count ways to express N as the sum of 1,3 and 4

Output Window