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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.