- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Python Program to Count number of binary strings without consecutive 1’

In this article, we will learn about the solution to the problem statement given below.

**Problem statement** − We are given a positive integer N, we need to count all possible distinct binary strings available with length N such that no consecutive 1’s exist in the string.

Now let’s observe the solution in the implementation below −

## Example

# count the number of strings def countStrings(n): a=[0 for i in range(n)] b=[0 for i in range(n)] a[0] = b[0] = 1 for i in range(1,n): a[i] = a[i-1] + b[i-1] b[i] = a[i-1] return a[n-1] + b[n-1] # main n=5 print("The number of strings: ",countStrings(n))

## Output

The number of strings: 13

All the variables are declared in the local scope and their references are seen in the figure above.

## Conclusion

In this article, we have learned about how we can make a Python Program to Count number of binary strings without consecutive 1’

- Related Questions & Answers
- C/C++ Program to Count number of binary strings without consecutive 1’s?
- Count number of binary strings without consecutive 1's in C
- Program to Count number of binary strings without consecutive 1’s in C/C++?
- Count Binary String without Consecutive 1's
- Program to find longest consecutive run of 1 in binary form of a number in C++
- Program to count the number of consistent strings in Python
- Python program to check if there are K consecutive 1’s in a binary number?
- Program to find concatenation of consecutive binary numbers in Python
- C# program to check if there are K consecutive 1’s in a binary number
- Python program to count pairs for consecutive elements
- Program to count number of ways to win at most k consecutive games in Python
- Count number of binary strings of length N having only 0’s and 1’s in C++
- Finding maximum number of consecutive 1's in a binary array in JavaScript
- Program to count number of fraction pairs whose sum is 1 in python
- Python program to count the pairs of reverse strings

Advertisements