Problem · Matrix
Write 'Y' on Matrix
Learn this problemProblem statement
You are given an odd n × n matrix containing only 0, 1, and 2.
The cells of the letter Y are both diagonals from the top corners through the center, followed by the center column from the center to the bottom. Choose one digit for all Y cells and a different digit for every non-Y cell.
Return the minimum number of cells that must change over all six ordered choices of distinct Y and background digits.
Function
writeLMatrix(matrix: int[][]) → intExamples
Example 1
matrix = [[1, 0, 2], [1, 2, 0], [0, 2, 0]]return = 2Using 2 for the Y and 0 for the background requires changing two cells.
Example 2
matrix = [[2, 0, 0, 0, 2], [1, 2, 1, 2, 0], [0, 1, 2, 1, 0], [0, 0, 2, 1, 1], [1, 1, 2, 1, 1]]return = 8Using 2 for the Y and 1 for all remaining cells requires changing the eight zeroes.
Constraints
5 ≤ matrix.length ≤ 990 ≤ matrix[i][j] ≤ 2