Sum of Each Matrix Column

Given a nonempty rectangular integer matrix, return an array containing the sum of each column in left-to-right order. Negative and zero values contribute…

Given a nonempty rectangular integer matrix, return an array containing the sum of each column in left-to-right order. Negative and zero values contribute normally.

1 to 1000 rows, 1 to 500 columns, at most 250,000 cells; every row has the same positive length. Every cell is an integer from -1000 through 1000. The visualizer uses matrices of at most 6 rows and 6 columns; larger valid inputs are execution-only.

Example 1: input matrix = [[3, -1, 4], [0, 5, -2]]; output [3, 4, 2]. The columns total 3 + 0 = 3, -1 + 5 = 4, and 4 + (-2) = 2, in that order.

Example 2: input matrix = [[-7]]; output [-7]. The only column contains -7, so its sole subtotal is -7.

Example 3: input matrix = [[-7, 0, 2]]; output [-7, 0, 2]. Each column has one value; their left-to-right totals are -7, 0, and 2.

Category: Arrays. Topic: arrays. Difficulty: Easy. Patterns: math.