note - see the Problem Source section at the vely bottom of the page for the original problem description :)
Once upon a time, in a land of square matrices filled with 0's, 1's, and 2's, there was a magical n x n matrix, where n was always an odd number. The wise mathematicians wanted to transform this matrix to create a grand letter "L" that would rise majestically from the upper-left corner down to the center of the matrix and stretch horizontally to the right corner. The "L" was formed by 1's, while the surrounding areas would remain as 0's and 2's. The challenge was to figure out the minimum number of cells that needed to be changed to achieve this enchanting design, ensuring that all the cells making up the "L" glowed with the number 1, while the background continued to shimmer with the magic of 0's and 2's. Thus, the quest began to determine how many cells would need to be altered to bring this vision to life!
Example 1:
Input: matrix = [[1, 0, 2], [1, 2, 0], [0, 2, 0]]
Output: 2
Explanation:To achieve the magical "L," the wise mathematicians discovered that the best way was to transform the 1 in the 0th row into a 2, and the 1 in the 1st row into a 0. This clever move allowed the 2's to create the enchanting shape of the letter "Y," while the 0's gracefully formed the background, enhancing the beauty of the design. With these delightful changes, the final matrix emerged, shimmering with the perfect blend of numbers, showcasing the magnificent "L" in all its glory.
matrix = [ [2, 0, 2], [0, 2, 0], [0, 2, 0], ]
Example 2:
Input: matrix = [[2, 0, 0, 0, 2], [1, 2, 1, 2, 0], [0, 1, 2, 1, 0], [1, 1, 2, 1, 1]]
Output: 8
Explanation:In this magical transformation, the 2's gracefully took shape to form the enchanting letter "Y." The wise mathematicians discovered that the best solution was to change all the 0's, a total of 8, into shimmering 1's, resulting in a grand total of 10 luminous 1's illuminating the matrix. With these clever adjustments, the final matrix emerged, radiating with the brilliance of the newly crafted "Y" and creating a mesmerizing display that captured the essence of their creative endeavor.
matrix = [ [2, 1, 1, 1, 2], [1, 2, 1, 2, 1], [1, 1, 2, 1, 1], [1, 1, 2, 1, 1], [1, 1, 2, 1, 1], ]
5 ≤ matrix.length ≤ 99
0 ≤ matrix[i][j] ≤ 2


input:
output: