Python map function to find row with maximum number of 1's Last Updated : 28 Jul, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 this problem in python quickly using map() function. Approach is very simple, find sum of all 1's in each row and then print index of maximum sum in a list because row having maximum 1 will also have maximum sum. Implementation: Python3 # Function to find the row with maximum number of 1's def maxOnes(input): # map sum function on each row of # given matrix # it will return list of sum of all one's # in each row, then find index of maximum element result = list(map(sum,input)) print (result.index(max(result))) # Driver program if __name__ == "__main__": input = [[0, 1, 1, 1],[0, 0, 1, 1],[1, 1, 1, 1],[0, 0, 0, 0]] maxOnes(input) Output2 Complexity : O(M*N) Comment More infoAdvertise with us Next Article Python map function to find row with maximum number of 1's S Shashank Mishra Follow Improve Article Tags : Python python-list Practice Tags : pythonpython-list Similar Reads Maximum length of consecutive 1's in a binary string in Python using Map function 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 p 1 min read Python Program for Maximum size square sub-matrix with all 1s Write a Python program for a given binary matrix, the task is to find out the maximum size square sub-matrix with all 1s. Recommended: Please solve it on "PRACTICE" first, before moving on to the solution.Approach: Let the given binary matrix be M[R][C]. The idea of the algorithm is to construct an 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 How to Find the First Empty Row of an Excel File in Python When working with data in Excel files, one common task is to find the first empty row where new data can be added. Whether you're automating a data entry process or performing data analysis, Python offers several methods to accomplish this task efficiently. In this article, we'll explore different a 2 min read Submatrix of given size with maximum 1's Given a binary matrix mat[][] and an integer K, the task is to find the submatrix of size K*K such that it contains maximum number of 1's in the matrix. Examples: Input: mat[][] = {{1, 0, 1}, {1, 1, 0}, {1, 0, 0}}, K = 2 Output: 3 Explanation: In the given matrix, there are 4 sub-matrix of order 2*2 15+ min read Like