Given a boolean 2D array, where each row is sorted. Find the row with the maximum number of 1s.
Example 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.
Complexity : O(M*N)
- Python | Find the Number Occurring Odd Number of Times using Lambda expression and reduce function
- Python program to find number of local variables in a function
- Find row number of a binary matrix having maximum number of 1s
- Python | Find maximum value in each sublist
- Python | Find Maximum difference pair
- Python program to find second maximum value in Dictionary
- Python | Find the sublist with maximum value in given nested list
- Find the row with maximum number of 1s
- Find row with maximum and minimum number of zeroes in given Matrix
- Find alphabet in a Matrix which has maximum number of stars around it
- Python | Pandas series.cummax() to find Cumulative maximum of a series
- Python | Find maximum length sub-list in a nested list
- Python | Find number of lists in a tuple
- Python | Find closest number to k in given list
- Analysis of Different Methods to find Prime Number in Python
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.