Trains the technique from
LeetCode 3071Minimum Operations to Write the Letter Y on a GridThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A square board of odd side is given as grid, each cell holding 0, 1 or 2. One repaint changes a single cell to any of the three values.
The wye is the set of cells on the two diagonals running down from the top corners as far as the middle cell, together with the cells straight below the middle cell. Every other cell is outside the wye.
The board shows a wye when every cell of the wye holds one value, every cell outside holds one value, and those two values differ. Return the fewest repaints that leave the board showing a wye.
Example 1
The wye holds the corners of the top row, the middle cell and the two cells below it, and those already read 1, 1, 1, 1, 1. Everything outside already reads 0, so the board already shows a wye.
Example 2
Every cell reads 0, so one of the two parts has to be repainted, and the wye is the smaller of the two.
Example 3
Painting the wye 2 leaves three of its five cells to change, and painting everything else 1 leaves two of the four outside cells to change.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def minimum_operations_to_write_y(grid: list[list[int]]) -> int:public int minimumOperationsToWriteY(int[][] grid)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.