{"id":"1b5e8c66-100e-4e78-9df7-5af624dc65cf","name":"Count Binary Strings","description":"1. You are given a number n.\r\n2. You are required to print the number of binary strings of length n with no consecutive 0's.","inputFormat":"A number n","outputFormat":"A number representing the number of binary strings of length n with no consecutive 0's.","constraints":"0 &lt; n &lt;= 45","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\r\nusing namespace std;\r\nint main() {\r\n \r\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main{\r\n\r\npublic static void main(String[] args) throws Exception {\r\n // write your code here\r\n }\r\n\r\n}"},"python":{"code":"print()"}},"points":10,"difficulty":"easy","sampleInput":"6","sampleOutput":"21","questionVideo":"https://www.youtube.com/embed/nqrXHJWMeBc?end=98","hints":[],"associated":[{"id":"387460e9-025c-41e2-a8fa-2c42d41a3d09","name":"what are the common conditions for storing an element in both of the dp arrays?","slug":"what-are-the-common-conditions-for-storing-an-element-in-both-of-the-dp-arrays","type":4},{"id":"bb5bb0c6-7cba-4186-809c-4564a3a2569d","name":"DP optimizes the solution by taking advantage of which of the following:","slug":"dp-optimizes-the-solution-by-taking-advantage-of-which-of-the-following","type":4},{"id":"f0bc0bd4-6351-4186-9d16-bcc74db3468e","name":"What will be the time complexity of Count Binary Strings","slug":"what-will-be-the-time-complexity-of-count-binary-strings","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"52d62581-1313-45fb-aaf0-1d72a45f6a50","name":"Dynamic Programming And Greedy For Beginners","slug":"dynamic-programming-and-greedy-for-beginners","type":0},{"id":"1c04bbdb-eb09-4a19-ac25-3900ef3d2568","name":"Count Binary Strings","slug":"count-binary-strings","type":1}],"next":{"id":"80c99904-3ac6-4d42-97f3-d71a3979889d","name":"Count Binary Strings","type":3,"slug":"count-binary-strings"},"prev":{"id":"799a3962-2b02-4700-8a7c-0047d8858c55","name":"Fractional Knapsack - Official","type":3,"slug":"fractional-knapsack-official"}}}

# Count Binary Strings

1. You are given a number n. 2. You are required to print the number of binary strings of length n with no consecutive 0's.

{"id":"1b5e8c66-100e-4e78-9df7-5af624dc65cf","name":"Count Binary Strings","description":"1. You are given a number n.\r\n2. You are required to print the number of binary strings of length n with no consecutive 0's.","inputFormat":"A number n","outputFormat":"A number representing the number of binary strings of length n with no consecutive 0's.","constraints":"0 &lt; n &lt;= 45","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\r\nusing namespace std;\r\nint main() {\r\n \r\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main{\r\n\r\npublic static void main(String[] args) throws Exception {\r\n // write your code here\r\n }\r\n\r\n}"},"python":{"code":"print()"}},"points":10,"difficulty":"easy","sampleInput":"6","sampleOutput":"21","questionVideo":"https://www.youtube.com/embed/nqrXHJWMeBc?end=98","hints":[],"associated":[{"id":"387460e9-025c-41e2-a8fa-2c42d41a3d09","name":"what are the common conditions for storing an element in both of the dp arrays?","slug":"what-are-the-common-conditions-for-storing-an-element-in-both-of-the-dp-arrays","type":4},{"id":"bb5bb0c6-7cba-4186-809c-4564a3a2569d","name":"DP optimizes the solution by taking advantage of which of the following:","slug":"dp-optimizes-the-solution-by-taking-advantage-of-which-of-the-following","type":4},{"id":"f0bc0bd4-6351-4186-9d16-bcc74db3468e","name":"What will be the time complexity of Count Binary Strings","slug":"what-will-be-the-time-complexity-of-count-binary-strings","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"52d62581-1313-45fb-aaf0-1d72a45f6a50","name":"Dynamic Programming And Greedy For Beginners","slug":"dynamic-programming-and-greedy-for-beginners","type":0},{"id":"1c04bbdb-eb09-4a19-ac25-3900ef3d2568","name":"Count Binary Strings","slug":"count-binary-strings","type":1}],"next":{"id":"80c99904-3ac6-4d42-97f3-d71a3979889d","name":"Count Binary Strings","type":3,"slug":"count-binary-strings"},"prev":{"id":"799a3962-2b02-4700-8a7c-0047d8858c55","name":"Fractional Knapsack - Official","type":3,"slug":"fractional-knapsack-official"}}}

Editor

# Count Binary Strings

easy

1. You are given a number n. 2. You are required to print the number of binary strings of length n with no consecutive 0's.

0 < n <= 45

## Format

A number n

### Output

A number representing the number of binary strings of length n with no consecutive 0's.

## Example

Sample Input

6

### Sample Output

21

Question Video

Discussions

Show Discussion

Related Resources