A tic-tac-toe style game scores a square board grid by adding the numbers on both diagonals: the one from top-left to bottom-right and the one from top-right to bottom-left.
Write diagonalTotal(grid) that returns that total. If the board has an odd size, the center cell is on both diagonals but counts only once.
Input: grid = [[2,0,1],[0,4,0],[3,0,5]] Output: 15
2 + 4 + 5 on one diagonal and 1 + 3 on the other; the center 4 is counted once.
Input: grid = [[1,1],[1,1]] Output: 4
An even board has no shared center, so all four cells count.
1 <= n <= 100-100 <= grid[r][c] <= 100Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #76 Diagonal Totals of a Board. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.