Heaviest Row
Every row of grid has the same number of cells. Add up the numbers in each row and return the index (counting from 0) of the row with the largest total. If several rows share the largest total, return the smallest of their indices.
Example 1
grid [[1,2,3],[4,5,6],[7,8,9]]
returns 2
The row totals are 6, 15 and 24, so row 2 is the heaviest.
Example 2
grid [[5,5],[9,1],[2,8]]
returns 0
All three rows add up to 10, so the smallest index, 0, wins the tie.
Constraints
1 <= rows, cols <= 10-100 <= grid[r][c] <= 100
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Grids problems
- Layer LabelsBeginner
- Mirror the RowsBeginner
- Rising DiagonalBeginner
- Snake ReadBeginner
- Spot the DifferencesBeginner
- Square on a Winding BoardBeginner
- Colony StepEasy
- Diagonal BandsEasy