- Related Questions & Answers
- C/C++ Program to Count number of binary strings without consecutive 1’s?
- Program to Count number of binary strings without consecutive 1’s in C/C++?
- Count number of binary strings without consecutive 1's in C
- Count Binary String without Consecutive 1's
- Python program to check if there are K consecutive 1’s in a binary number?
- Count number of binary strings of length N having only 0’s and 1’s in C++
- C# program to check if there are K consecutive 1’s in a binary number
- Program to find longest consecutive run of 1 in binary form of a number in C++
- Maximum length of consecutive 1’s in a binary string in Python using Map function
- 1’s and 2’s complement of a Binary Number?
- Binary representation of next greater number with same number of 1’s and 0’s in C Program?
- C# program to find the length of the Longest Consecutive 1’s in Binary Representation of a given integer
- Java program to find the length of the Longest Consecutive 1’s in Binary Representation of a given integer
- Count the number of 1’s and 0’s in a binary array using STL in C++
- Count 1’s in a sorted binary array in C++

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

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 −

# 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))

The number of strings: 13

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

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

Advertisements