2679. Sum in a Matrix

Difficulty:
Related Topics:
Similar Questions:

    Problem

    You are given a 0-indexed 2D integer array nums. Initially, your score is 0. Perform the following operations until the matrix becomes empty:

    Return **the final **score.

    Example 1:

    Input: nums = [[7,2,1],[6,4,2],[6,5,3],[3,2,1]]
    Output: 15
    Explanation: In the first operation, we remove 7, 6, 6, and 3. We then add 7 to our score. Next, we remove 2, 4, 5, and 2. We add 5 to our score. Lastly, we remove 1, 2, 3, and 1. We add 3 to our score. Thus, our final score is 7 + 5 + 3 = 15.
    

    Example 2:

    Input: nums = [[1]]
    Output: 1
    Explanation: We remove 1 and add it to the answer. We return 1.
    

    Constraints:

    Solution (Java)

    class Solution {
        public int matrixSum(int[][] nums) {
            int score = 0;
            int n = nums.length;
            int m = nums[0].length;
            for(int[] a :nums)
            {
                Arrays.sort(a);
            }
            for(int i=0;i<m;i++)
            {
                int max = 0;
                for(int j=0;j<n;j++)
                {
                    max = Math.max(max,nums[j][i]);
                }
                score+=max;
            }
            return score;
        }
    }
    

    Explain:

    nope.

    Complexity: