Interview Query

Sum of Matrix Elements

Start Timer

0:00:00

Upvote
0
Downvote
Save question
Mark as completed
View comments (7)
Next question

“Suppose you are given a matrix of integers. Your task is to write a function that returns the sum of the elements in the matrix.

Example 1:

Input:

matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

Output:

matrix_sum(matrix) -> 45

Example 2:

Input:

matrix = [[-1, -2, -3], [-4, -5, -6], [-7, -8, -9]]

Output:

matrix_sum(matrix) -> -45

The function should be able to handle both positive and negative integers and should return the sum as an integer.

.
.
.
.
.


Comments

Loading comments.