We are given a binary string containing 1’s and 0’s. Find maximum length of consecutive 1’s in it.
Input : str = '11000111101010111' Output : 4
We have existing solution for this problem please refer Maximum consecutive one’s (or zeros) in a binary array link. We can solve this problem within single line of code in Python. Approach is very simple,
- Separate all sub-strings of consecutive 1’s separated by zeros using split() method of string.
- Print maximum length of splited sub-strings of 1’s.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Length of longest consecutive ones by at most one swap in a Binary String
- Maximum Consecutive Zeroes in Concatenated Binary String
- Find the number of binary strings of length N with at least 3 consecutive 1s
- Check if a binary string contains consecutive same or not
- Maximum consecutive repeating character in string
- Binary string with given frequencies of sums of consecutive pairs of characters
- Count of binary strings of length N with even set bit count and at most K consecutive 1s
- Binary String of given length that without a palindrome of size 3
- Check if a binary string contains all permutations of length k
- Count maximum-length palindromes in a String
- Find the first maximum length even word from a string
- Maximum even length sub-string that is permutation of a palindrome
- Number of sub-sequences of non-zero length of a binary string divisible by 3
- Generate all binary strings of length n with sub-string "01" appearing exactly twice
- Maximum length substring with highest frequency in a string
- Maximum length prefix of one string that occurs as subsequence in another
- Maximum length of balanced string after swapping and removal of characters
- Length of the smallest sub-string consisting of maximum distinct characters
- Maximum difference of zeros and ones in binary string
- Find the maximum possible Binary Number from given 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 firstname.lastname@example.org. 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.