DatabricksOA #7
Letter "Y" on a Square Matrix
Estimated MediumJudge-ready
Topics (AI-labelled)HashingIn-place Arrays
You are given a square matrix of odd order whose cell values are only 0, 1, or 2. Choose one digit as the digit of the Y: its upper part consists of the two diagonals running from the top-left corner to the center and from the top-right corner to the center, and below the center it is the middle column; every cell outside the Y must become one other, different digit. Find the minimum number of cells that must be changed.
Standard input/output, this site's supplementary ranges, and the examples follow this problem's description.
Input
The first line contains an odd n (1≤n≤99), followed by n lines, each with n values of 0, 1, or 2. The upper bound on n is a site supplement.
Output
Output the minimum number of cells to change.
Example 1
Input:
3
1 0 1
2 1 2
2 1 2
Output:
1
Example 2
Input:
5
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
Output:
7
Example 3
Input:
3
0 1 2
1 2 0
2 0 1
Output:
4
Editorial
Loading solution…