Maximum length of consecutive 1's in a binary string in Python using Map function Last Updated : 27 Jul, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report We are given a binary string containing 1's and 0's. Find the maximum length of consecutive 1's in it. Examples: Input : str = '11000111101010111' Output : 4 We have an existing solution for this problem please refer to Maximum consecutive one’s (or zeros) in a binary array link. We can solve this problem within single line of code in Python. The approach is very simple, Separate all sub-strings of consecutive 1's separated by zeros using split() method of string.Print maximum length of split sub-strings of 1's. Implementation: Python # Function to find Maximum length of consecutive 1's in a binary string def maxConsecutive1(input): # input.split('0') --> splits all sub-strings of consecutive 1's # separated by 0's, output will be like ['11','1111','1','1','111'] # map(len,input.split('0')) --> map function maps len function on each # sub-string of consecutive 1's # max() returns maximum element from a list print max(map(len,input.split('0'))) # Driver program if __name__ == "__main__": input = '11000111101010111' maxConsecutive1(input) Output4 Time complexity : O(n) Auxiliary Space : O(1) Comment More infoAdvertise with us Next Article Python Program to Count number of binary strings without consecutive 1's S Shashank Mishra Follow Improve Article Tags : Python Python-DSA Practice Tags : python Similar Reads Check if a given string is binary string or not - Python The task of checking whether a given string is a binary string in Python involves verifying that the string contains only the characters '0' and '1'. A binary string is one that is composed solely of these two digits and no other characters are allowed. For example, the string "101010" is a valid bi 3 min read Python Program to Count number of binary strings without consecutive 1's Write a Python program for a given positive integer N, the task is to count all possible distinct binary strings of length N such that there are no consecutive 1s. Examples: Input: N = 2Output: 3// The 3 strings are 00, 01, 10 Input: N = 3Output: 5// The 5 strings are 000, 001, 010, 100, 101 Recomme 4 min read Python - Check if there are K consecutive 1's in a binary number The task is to check if a binary number (a string of 0s and 1s) has k consecutive 1s in it. The goal is to figure out if this pattern exists in the easiest and fastest way possible. Using for loopThis method works by going through the string once and keeping track of how many '1's appear in a row. I 3 min read Python map function to find row with maximum number of 1's Given a boolean 2D array, where each row is sorted. Find the row with the maximum number of 1s. Examples: Input: matrix = [[0, 1, 1, 1], [0, 0, 1, 1], [1, 1, 1, 1], [0, 0, 0, 0]] Output: 2 We have existing solution for this problem please refer Find the row with maximum number of 1's. We can solve t 1 min read Find all the patterns of â1(0+)1â in a given string using Python Regex A string contains patterns of the form 1(0+)1 where (0+) represents any non-empty consecutive sequence of 0âs. Count all such patterns. The patterns are allowed to overlap. Note : It contains digits and lowercase characters only. The string is not necessarily a binary. 100201 is not a valid pattern. 2 min read Different ways to Invert the Binary bits in Python We know how binary value for numbers look like. For example, the binary value for 10 (Number Ten) is 1010 (binary value).Sometimes it is required to inverse the bits i.e., 0's to 1's ( zeros to ones) and 1's to 0's (ones to zeros). Here are there few ways by which we can inverse the bits in Python.U 3 min read Like