Given a binary string and a number m, the task is to check if the string has m consecutive 1’s or 0’s
Input : str = “001001”, m = 2
Output : YES
Input : str = “1000000001”, m = 10
Output : NO
The approach is to count the consecutive 1’s or 0’s by traversing in the binary string. While traversing in the binary string, keep a count of the number of 1’s or 0’s appearing consecutively. If there are M consecutive 1’s or 0’s, return True else return False.
Given below is the implementation of the above approach:
Time Complexity: O(N), where N is the length of the binary string.
- Check if a binary string contains consecutive same or not
- Check if a binary string has two consecutive occurrences of one everywhere
- Check if the string contains consecutive letters and each letter occurs exactly once
- Python | Check if there are K consecutive 1's in a binary number
- Remove all consecutive duplicates from a string using STL in C++
- Remove three consecutive duplicates from string
- Remove all consecutive duplicates from the string
- Remove consecutive vowels from string
- Consecutive sequenced numbers in a string
- Check if absolute difference of consecutive nodes is 1 in Linked List
- Group consecutive characters of same type in a string
- Maximum consecutive repeating character in string
- Reduce the string by removing K consecutive identical characters
- Maximum Consecutive Zeroes in Concatenated Binary String
- Length of longest consecutive ones by at most one swap in a Binary String
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.