Matrix Diagonal Sum

Easy
Arrays Array Matrix

Given an n×n matrix, return the sum of both diagonals (count center once for odd n).

Constraints

1 ≤ n ≤ 100

Examples

Example 1:
Input: 1 2 3 4 5 6 7 8 9
Output: 25
Example 2:
Input: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Output: 8
▲ Console

Install Talent Arabia

Get instant access to jobs and career tools on your device.