Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Sum in a Matrix

XPChallenge Points: 20
levelLevel: Medium

You are given a 2D list nums. Your score begins at 0.
In every round, you must select the largest value from each row and remove those values from the matrix.
Among all removed values in that round, find the greatest one and add it to your score.
Continue performing these rounds until all values are removed from the matrix.
Return the total score obtained after all rounds.

Example 1:

Input: nums = [[10,3,8],[4,6,5],[9,1,2]]

Output: 22

Explanation:

Round 1 Removed: 10, 6, 9 → max is 10 → score = 10 Round 2 Removed: 8, 5, 2 → max is 8 → score = 10 + 8 = 18 Round 3 Removed: 3, 4, 1 → max is 4 → score = 18 + 4 = 22

Example 2:

Input: nums = [[5,5],[5,5]]

Output: 10

Explanation:

Round 1: removed values are 5,5 → max = 5 Round 2: removed values are 5,5 → max = 5

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result