0 out of 464 challenges solved

Sort Matrix by Row Sum

Write a function `sort_matrix(matrix)` that takes a 2D list (matrix) as input and returns a new matrix where the rows are sorted in ascending order based on the sum of their elements.

#### Example Usage
```python [main.nopy]
matrix = [[1, 2, 3], [2, 4, 5], [1, 1, 1]]
result = sort_matrix(matrix)
print(result)  # Output: [[1, 1, 1], [1, 2, 3], [2, 4, 5]]

matrix = [[5, 8, 9], [6, 4, 3], [2, 1, 4]]
result = sort_matrix(matrix)
print(result)  # Output: [[2, 1, 4], [6, 4, 3], [5, 8, 9]]
```

#### Constraints
- The input matrix will be a list of lists, where each inner list represents a row.
- Each row will contain integers.
- The matrix will have at least one row and one column.
def sort_matrix(matrix):
    """
    Sorts a matrix in ascending order based on the sum of its rows.

    Args:
        matrix (list of list of int): The input 2D list.

    Returns:
        list of list of int: The sorted matrix.
    """
    # Implement the sorting logic here
    pass