Given K and a binary number, check if there exists k consecutive 1’s in the binary number.
Input : binary number = 101010101111 k = 4 Output : yes Explanation: at the last 4 index there exists 4 consecutive 1's Input : binary number = 11100000 k=5 Output : no Explanation: There is a maximum of 3 consecutive 1's in the given binary.
Approach: Create a new string with k 1’s. Using if condition check if there is new in s. In python if new in s: checks if there is any existence if new in s, hence returns true if there is else it returns a false.
Below is the Python implementation of the above approach:
- Check if a binary string contains consecutive same or not
- Check if a binary string has two consecutive occurrences of one everywhere
- Count number of binary strings without consecutive 1’s : Set 2
- Count number of binary strings without consecutive 1's
- Find the number of binary strings of length N with at least 3 consecutive 1s
- Python Map | Length of the Longest Consecutive 1's in Binary Representation of a given integer
- Python | Check if list contains consecutive numbers
- Python | Check if binary representation is palindrome
- Python Dictionary | Check if binary representations of two numbers are anagram
- Maximum consecutive one’s (or zeros) in a binary array
- Check if a string has m consecutive 1's or 0's
- Length of longest consecutive ones by at most one swap in a Binary String
- Maximum Consecutive Zeroes in Concatenated Binary String
- Maximum consecutive one’s (or zeros) in a binary circular array
- Binary string with given frequencies of sums of consecutive pairs of characters
- Check if binary representations of 0 to N are present as substrings in given binary string
- Count of Binary strings of length N having atmost M consecutive 1s or 0s alternatively exactly K times
- Number Guessing Game in Python using Binary Search
- Python program to convert decimal to binary number
- Python program to check whether a number is Prime or not
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.