Click4Ai

29.

Easy

Write a function row_sums(matrix) that returns a list where each element is the sum of the corresponding row in the matrix. Do not use np.sum().

Example:

Input: matrix = [[1, 2, 3],

[4, 5, 6],

[7, 8, 9]]

Output: [6, 15, 24]

**Explanation:** Row 0: 1+2+3=6, Row 1: 4+5+6=15, Row 2: 7+8+9=24

Constraints:

  • Matrix dimensions: 1 <= rows, cols <= 100
  • Return a list of integers/floats
  • Test Cases

    Test Case 1
    Input: [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
    Expected: [6, 15, 24]
    Test Case 2
    Input: [[1, 1], [2, 2], [3, 3]]
    Expected: [2, 4, 6]
    Test Case 3
    Input: [[10, 20, 30]]
    Expected: [60]
    + 2 hidden test cases