Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Write the Letter Y on a Grid

med
30 min
Try to solve the Minimum Operations to Write the Letter Y on a Grid problem.

Statement

You are given a 00-indexed n x n grid where n is odd, and each cell grid[r][c] contains a value of 00, 11, or 22.

A cell is considered part of the Letter Y if it belongs to any of the following segments:

  • The diagonal starting at the top-left cell and ending at the center cell of the grid.

  • The diagonal starting at the top-right cell and ending at the center cell of the grid.

  • The vertical line starting at the center cell and ending at the bottom border of the grid.

The Letter Y is considered written on the grid if and only if:

  • All cells belonging to Y share the same value.

  • All cells not belonging to Y share the same value.

  • The value of Y cells is different from the value of non-Y cells.

In one operation, you may change the value of any cell to 00, 11, or 22. Return the minimum number of operations required to write the Letter Y on the grid.

Constraints:

  • 33 \leq n 49\leq 49

  • n ==== grid.length ==== grid[i].length

  • 00 \leq grid[i][j] 2\leq 2

  • n is odd

Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Write the Letter Y on a Grid

med
30 min
Try to solve the Minimum Operations to Write the Letter Y on a Grid problem.

Statement

You are given a 00-indexed n x n grid where n is odd, and each cell grid[r][c] contains a value of 00, 11, or 22.

A cell is considered part of the Letter Y if it belongs to any of the following segments:

  • The diagonal starting at the top-left cell and ending at the center cell of the grid.

  • The diagonal starting at the top-right cell and ending at the center cell of the grid.

  • The vertical line starting at the center cell and ending at the bottom border of the grid.

The Letter Y is considered written on the grid if and only if:

  • All cells belonging to Y share the same value.

  • All cells not belonging to Y share the same value.

  • The value of Y cells is different from the value of non-Y cells.

In one operation, you may change the value of any cell to 00, 11, or 22. Return the minimum number of operations required to write the Letter Y on the grid.

Constraints:

  • 33 \leq n 49\leq 49

  • n ==== grid.length ==== grid[i].length

  • 00 \leq grid[i][j] 2\leq 2

  • n is odd