Trains the technique from
LeetCode 1572Matrix Diagonal SumThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A square panel panel has as many rows as columns. Add up the tiles along the diagonal running from the top-left corner to the bottom-right one, and the tiles along the diagonal running from the top-right corner to the bottom-left one. A tile lying on both diagonals is counted only once.
Return that total.
Example 1
On a two by two panel the two diagonals between them cover all four tiles.
Example 2
The first diagonal holds the three 3 tiles for 9. The other adds the two corner 1 tiles, while the middle tile lies on both and is counted once.
Example 3
The two 100 tiles sit on the first diagonal and the two 1 tiles on the other.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def diagonal_sum(panel: list[list[int]]) -> int:public int diagonalSum(int[][] panel)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.