All problems
0728EasyArrayMatrix

Busiest Row Of The Punch Sheet

Tracked in this browser only
Write code

Trains the technique from

LeetCode 2643Row With Maximum Ones

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A punch sheet is recorded as a grid sheet of 0s and 1s, where sheet[r][c] is 1 when the cell in row r and column c has been punched and 0 when it has not. Every row of the sheet has the same number of columns.

Find the row that holds the most punched cells. If several rows hold the same number of punched cells, and that is the most, take the one with the smallest row index.

Return a two-entry array [row, punches], where row is the index of that row and punches is how many punched cells it holds.

Examples

Example 1

Input
sheet = [[0, 1, 1, 0], [1, 0, 0, 0], [0, 1, 1, 1]]
Output
[2, 3]

The rows hold 2, 1 and 3 punched cells, so row 2 with its 3 punches is reported.

Example 2

Input
sheet = [[1, 0, 1], [0, 1, 0], [1, 1, 0]]
Output
[0, 2]

Rows 0 and 2 both hold 2 punched cells and row 1 holds 1. The tie between rows 0 and 2 goes to the smaller index.

Example 3

Input
sheet = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
Output
[0, 0]

Nothing is punched, so every row holds 0 and the smallest index wins the tie.

Constraints

  • 1 <= sheet.length <= 100
  • 1 <= sheet[i].length <= 100
  • 0 <= sheet[i][j] <= 1
  • Every row of sheet has the same number of columns.

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def busiest_row(sheet: list[list[int]]) -> list[int]:
Java
public int[] busiestRow(int[][] sheet)
September 7
Apply