Sum Every Third Spiral Element
Problem statement
Traverse a square integer matrix in clockwise spiral order starting at the top-left. Return the sum of elements at zero-based spiral indices divisible by three.
Function
sumEveryThirdSpiral(matrix: int[][]) → longExamples
Example 1
matrix = [[1,2,3],[4,5,6],[7,8,9]]return = 14The selected spiral values are 1, 6, and 7.
Example 2
matrix = [[5]]return = 5The only value has spiral index zero.
Constraints
1 <= matrix.length == matrix[i].length <= 500