1722. Row Max Rounds

Easy1.5 points estimatedMatrixSortingHeap

A quiz show has several contestants, each holding a row of point cards in grid; every row has the same number of cards. The show runs in rounds. In each round every contestant lays down their highest remaining card, and the host awards the single highest of those laid-down cards to the table score. The cards laid down are discarded, and rounds continue until all rows are empty.

Return the final table score as a long. Equal cards are fine, since only the values matter. Sorting every row first lets you read the winning card of each round directly, giving O(r * c log c) time and O(r * c) space for the sorted copy.

Example 1

Input:
grid = [[4,2,9],[1,7,3]]
Output:
15
Explanation:

Round one removes 9 and 7 (score 9), round two removes 4 and 3 (score 4), round three removes 2 and 1 (score 2), for 15.

Example 2

Input:
grid = [[5]]
Output:
5
Explanation:

A single value is removed in one round, so the score is 5.

Example 3

Input:
grid = [[3,3],[3,3],[3,3]]
Output:
6
Explanation:

Each of the two rounds adds a 3, so the score is 6.

Constraints

1 ≤ rows, cols ≤ 50

1 ≤ grid[i][j] ≤ 106

How this problem is judged

Answers
Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.
Time per case
Python 4,000 msC++ 1,000 msJava 2,000 msJavaScript 2,000 msTypeScript 2,000 ms

Expected complexity

Time
O(r * c log c)
Space
O(r * c)

What the author was aiming for. Your own solution is not measured against it.

Asked in an interview

Were you asked this in an interview? Say where, anonymously.

Code
Loading the editor…