Problem

Return the sum of all elements on the outer border of a non-empty rectangular grid (each border cell counted once).

Examples

  • borderSum([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) -> 40
  • borderSum([[5, 1], [2, 3]]) -> 11
Compile and test (Ctrl+Enter)