Ctrl K

Rounds of Row Maximums

Medium
You are given a table grid whose rows all have the same length. The score starts at zero. While the table is not empty, play a round: 1. Remove the largest number from every row (if there are ties, any one of them). 2. Take the largest of the numbers removed this round and add it to the score. Return the final score.
Example 1
grid=[[4, 9, 1], [8, 2, 8]] → 19

Round 1 removes 9 and 8 and scores 9. Round 2 removes 4 and 8 and scores 8. Round 3 removes 1 and 2 and scores 2. Total 9 + 8 + 2 = 19.

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

A single round takes 3, 0 and 5, scoring 5.

Constraints
  • 1 ≤ len(grid) ≤ 300
  • 1 ≤ len(grid[i]) ≤ 500, all rows have the same length
  • 0 ≤ grid[i][j] ≤ 1000
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPeel Off the Row Maximums EasyK-th Smallest in a Sorted Grid MediumShuttle Seat Plan MediumK-th Largest Corner XOR MediumThree Heaviest Diamonds Medium
loading Python…
Input
grid=[[4, 9, 1], [8, 2, 8]]
Expected
19

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