Geeksforgeeks

X

DAYS

:

HOUR

:

MINS

:

SEC

Error

Copied to Clipboard

Given a number **N**, find the number of binary strings of length **N **that contains consecutive 1's in them.

**Example 1:**

Input:N = 2Output:1Explanation:There are 4 strings of length 2, the strings are 00, 01, 10, and 11. Only the string 11 has consecutive 1's.

**Example 2:**

Input:N = 5Output:19Explanation:There are 19 strings having consecutive 1's.

**Your Task:**

You don't need to read input or print anything. Your task is to complete the function numberOfConsecutiveOnes() which takes an integer N and returns the number of binary strings** **that contain consecutive 1's in them.

**Expected Time Complexity:** O(N)

**Expected Auxiliary Space:** O(N)

**Constraints**

2 <= **N **<=30

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

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login 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?

YesLoading...

Trail of ones

...