Skip to content

Practice Minimum Operations to Write the Letter Y on a Grid

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3071
LeetCode Problem

Minimum Operations to Write the Letter Y on a Grid

Problem Statement

Given an odd-sized n by n grid containing 0, 1, and 2, form a Y from the two diagonals connecting the top corners to the center and the vertical line connecting the center to the bottom edge. Every Y cell must have one common value, and every other cell must have another common value different from the Y value. One operation changes a cell to 0, 1, or 2. Return the fewest operations needed.

Source: Minimum Operations to Write the Letter Y on a Grid on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
grid = [[1,2,2],[1,1,0],[0,1,0]]
Output
3

# Example 2

Input
grid = [[0,1,0,1,0],[2,1,0,1,2],[2,2,2,0,1],[2,2,2,2,2],[2,1,2,2,2]]
Output
12

Constraints

3 <= n <= 49
n == grid.length == grid[i].length
0 <= grid[i][j] <= 2
n is odd.

Related LeetCode Problems

Practice more problems similar to Minimum Operations to Write the Letter Y on a Grid.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.