Trains the technique from
LeetCode 1975Maximum Matrix 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 grid grid holds whole numbers, some of them below zero. One move picks two cells sharing a side and turns the sign of both of them.
Return the largest total the grid's cells can add up to after any number of moves.
Example 1
One cell is below zero, and every move turns two signs, so the count of negatives can only change by two. One cell must stay negative, and the cheapest to leave is the smallest in size.
Example 2
One cell is below zero again, but a cell holding nothing costs nothing to leave negative, so every other cell can be made positive.
Example 3
Two cells are below zero, so both can be turned positive and the whole grid adds up in size.
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 max_matrix_sum(grid: list[list[int]]) -> int:public long maxMatrixSum(int[][] grid)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.