[Java] Simple one pass solution O(n^2)
The logic is very simple, If you iterate it maximum number of times, you can get rid of all the negatives if :\n1. There is a ZERO as a value in the matrix \n2.
The logic is very simple, If you iterate it maximum number of times, you can get rid of all the negatives if :\n1. There is a ZERO as a value in the matrix \n2. Count of negative characters are even.\n\nElse you can end up having only 1 negative number.\nFor that, choose the min number of absolute values in the matrix.\n\n\tpublic long maxMatrixSum(int[][] matrix) {\n\t\t\tint negCount = 0;\n\t\t\tlong totalSum = 0;\n\t\t\tint lowest = Integer.MAX_VALUE;\n\t\t\tboolean ifZeroPresent = false;\n\t\t\tfor(int i = 0 ; i < matrix.length ; i++) {\n\t\t\t\tfor(int j = 0 ; j < matrix.length ; j++) {\n\t\t\t\t\tif(matrix[i][j] < 0)  negCount++;\n\t\t\t\t\tint num = Math.abs(matrix[i][j]);\n\t\t\t\t\ttotalSum += num;\n\t\t\t\t\tlowest = Math.min(num, lowest);\n\t\t\t\t\tif(num == 0) ifZeroPresent = true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif(negCount % 2 == 1 && !ifZeroPresent) {\n\t\t\t\ttotalSum -= 2*lowest;\n\t\t\t}\n\t\t\treturn totalSum;\n\t\t}
['Java']