Consecutive 1's not allowed
Medium Accuracy: 48.5% Submissions: 14403 Points: 4

Given a positive integer N, count all possible distinct binary strings of length N such that there are no consecutive 1’s. Output your answer modulo 10^9 + 7.

Example 1:

N = 3
Output: 5
Explanation: 5 strings are (000,
001, 010, 100, 101).

Example 2:

N = 2
Output: 3
Explanation: 3 strings are

Your Task:
Complete the function countStrings() which takes single integer n, as input parameters and returns an integer denoting the answer. You don't to print answer or take inputs. 

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

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.


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


All Submissions

My Submissions:

Login to access your submissions.

Consecutive 1's not allowed

Output Window