You are given an n x n integer matrix. You can do the following operation any number of times: choose two adjacent elements (sharing a border) and multiply each of them by -1. Return the maximum possible sum of the matrix elements.
You are given an n x n integer matrix. You can do the following operation any number of times: choose two adjacent elements (sharing a border) and multiply each of them by -1. Return the maximum possible sum of the matrix elements.
Example 1:
Input: {"matrix":[[1,-1],[-1,1]]}
Output: 4
Constraints:
n=matrix.length=matrix[i].length
2≤n≤250
−105≤matrix[i][j]≤105
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"matrix":[[1,-1],[-1,1]]}
An operation flips the signs of two adjacent cells. Chaining operations moves a minus sign anywhere, so only how many negatives there are matters.