Python map function to find row with maximum number of 1's Last Updated : 28 Jul, 2022 Comments Improve Suggest changes 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 : Matrix Python DSA python-list Practice Tags : Matrixpythonpython-list Similar Reads Find the row with maximum number of 1s Given a binary 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 0Output: 2Explanation: Row = 2 has maximum number of 1s, that is 4.Input matrix : 0 0 1 1 0 1 1 1 0 0 1 1 0 0 0 0Output: 1Explanation: Row = 1 has max 15+ min read Find row with maximum and minimum number of zeroes in given Matrix Given a 2D matrix containing only zeroes and ones, where each row is sorted. The task is to find the row with the maximum number of 0s and the row with minimum number of 0s.Example: Input: mat[][] = { {0, 1, 1, 1}, {0, 0, 1, 1}, {1, 1, 1, 1}, {0, 0, 0, 0}} Output: Row with min zeroes: 3 Row with max 11 min read Maximum Number of Ones in Binary Matrix Given a binary matrix mat[][] with dimensions m * n, and any square sub-matrix of mat of size len * len has at most k ones. The task is to return the maximum possible number of ones that the matrix mat can have. Example: Input: m = 3, n = 3, len = 2, k = 1Output: 4Explanation: In a 3*3 matrix, no 2* 8 min read 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 Maximum sub-matrix area having count of 1's one more than count of 0's Given a N x N binary matrix. The problem is finding the maximum area sub-matrix having a count of 1's one more than count of 0's. Examples: Input : mat[][] = { {1, 0, 0, 1}, {0, 1, 1, 1}, {1, 0, 0, 0}, {0, 1, 0, 1} } Output : 9 The sub-matrix defined by the boundary values (1, 1) and (3, 3). { {1, 0 15 min read Count number of 1's at specific position in a matrix - II Given a binary matrix mat[][] of size m*n (0-based indexing), the task is to return the total number of 1's in the matrix that follows the below two rules. i.e: Row R and column C both contain exactly N number of 1's.All rows with 1's in column C should be the same as the 1's present in row R.Exampl 13 min read Maximum number of consecutive 1's in binary representation of all the array elements Given an array arr[] of N elements, the task is to find the maximum number of consecutive 1's in the binary representation of an element among all the elements of the given array. Examples: Input: arr[] = {1, 2, 3, 4} Output: 2 Binary(1) = 01 Binary(2) = 10 Binary(3) = 11 Binary(4) = 100 Input: arr[ 6 min read Python - Find maximum value in each sublist Finding the maximum value in each sublist involves iterating through a list of lists and identifying the largest element within each sublist. This operation is useful for analyzing data sets, and extracting the most significant values from grouped information. In this article, we will explore method 2 min read Find Column with Maximum Zeros in Matrix Given a matrix(2D array) M of size N*N consisting of 0s and 1s only. The task is to find the column with the maximum number of 0s. If more than one column exists, print the one which comes first. If the maximum number of 0s is 0 then return -1. Examples: Input: N = 3, M[][] = {{0, 0, 0}, {1, 0, 1}, 5 min read Like