The Maximum Matrix Sum coding problem gives you an n×n matrix of integers. In one operation, you can negate any two adjacent elements (sharing an edge). You can perform any number of operations. Maximize the sum of all elements in the matrix after any sequence of operations. The key insight is that you can "move" a negative sign around the matrix by flipping adjacent pairs.
Honeywell, Microsoft, Amazon, and Google use this problem to test mathematical reasoning under constraints. Candidates who observe that negatives can be "transported" anywhere on the matrix (by flipping adjacent pairs repeatedly) realize the only limitation is parity: you can flip any even number of negatives to positive, but if there's an odd count of negatives, one must remain. This transforms the problem into a simple greedy observation.
Greedy observation: Count the number of negative values. If it's even, you can make all values non-negative — sum all absolute values. If it's odd, you must keep one negative, so negate the element with the smallest absolute value and sum all other absolute values. The answer is sum(|all elements|) - 2 * min(|all elements|) when the negative count is odd, or sum(|all elements|) when even.
Matrix: [[1, -1], [-1, 1]]
Matrix: [[1, 2, 3], [-1, -2, -3], [1, 2, 3]]
For the Array Matrix Greedy interview pattern, look for parity-based invariants whenever the problem involves flipping or negating elements. The transformation "what can I achieve?" often boils down to a simple parity condition. State the invariant explicitly in the interview — it demonstrates mathematical insight that impresses interviewers.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Find Valid Matrix Given Row and Column Sums | Medium | Solve | |
| Max Increase to Keep City Skyline | Medium | Solve | |
| Reconstruct a 2-Row Binary Matrix | Medium | Solve | |
| Minimum Operations to Make Columns Strictly Increasing | Easy | Solve | |
| Score After Flipping Matrix | Medium | Solve |