Sum of Row Maxima
easy
Given a 2D matrix composed of integers, calculate the sum of the maximum values of each row. A matrix row is an array that may contain any integer including negatives.
Example 1
Input
[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]
Output
24
Explanation. The maximum numbers from each row are 3, 6, and 9. The sum of these numbers is 3+6+9 = 18.
Example 2
Input
[ [ -1, -2, -3 ], [ 4, 0, -1 ], [ 5, 2, 8 ] ]
Output
10
Explanation. The maximum numbers from each row are -1, 4, and 8. The sum of these numbers is -1+4+8 = 11.
Example 3
Input
[ [ 7 ], [ 10 ], [ 5 ] ]
Output
22
Explanation. There is only one value in each row: 7, 10, and 5. The sum of these numbers is 7+10+5 = 22.
Follow-up: How would your solution change if the matrix could also include non-integer numbers?
Constraints:
1. The matrix will not be empty.\n2. Each row in the matrix will contain at least one element.