Ctrl K

The Row With the Most Ones

Easy
You get a matrix grid of zeros and ones. Find the row with the most 1s and return a list of two numbers: that row's index (0-based) and how many 1s it has. If several rows tie, pick the one with the smallest index.
Example 1
grid=[[1, 0, 0], [1, 1, 0], [0, 1, 1]] → [1, 2]

Rows 1 and 2 both have two 1s, the maximum. The smaller index, 1, wins.

Example 2
grid=[[0, 0], [0, 0]] → [0, 0]

There are no 1s anywhere, so every row ties and row 0 is chosen with a count of 0.

Example 3
grid=[[0, 1, 0, 1], [1, 1, 1, 0]] → [1, 3]
Constraints
  • 1 ≤ number of rows, number of columns ≤ 100
  • All rows have the same length
  • Every cell is 0 or 1
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsCrossword That Reads Both Ways EasyIsland Coastline Length EasyRepack the Tray EasyBlur the Pixels EasyPaint Bucket Tool Easy
loading Python…
Input
grid=[[1, 0, 0], [1, 1, 0], [0, 1, 1]]
Expected
[1, 2]

Run checks the first 3 tests in your browser. Submit checks all 74 tests on the server, hidden ones included.