Facebook Interview Question
Anonymous User
1792

Given a n *n matrix, your task is to find the sum of all its borders. n is an even number.

Input:
[[9, 7, 4, 5],
[1, 6, 2, -6],
[12, 20, 2, 0],
[-5, -6, 7, -2]]
Output:
[26, 30]
Explanation:
We have two border here:
[9,7,4,5,-6,0,-2,7,-6,-5,12,1] as the first border, the sum of this border is 26
[6,2,2,20] as the second border, the sum of this border is 30
Thus, the result is [26, 30]

Can anyone share your thought and code on this question? Thanks.

Comments (10)
No comments yet.