Tap here to switch tabs
Problem
Submissions

Problem: Disconnect Path in a Binary Matrix by at Most One Flip

Try to solve the Disconnect Path in a Binary Matrix by at Most One Flip problem.

Statement

You are given a binary matrix grid of size m ×\times n.

From any cell (r,c)(r, c), you are permitted to move to (r+1,c)(r + 1, c) or (r,c+1)(r, c + 1) as long as the destination cell contains the value 11.

The matrix is disconnected if there is no valid path from the top left cell (0,0)(0, 0) to the bottom right cell (m −1- 1, n −1- 1).

You are allowed to flip the value of at most one cell from 11 to 00, excluding the cells (0,0)(0, 0) and (m −1- 1, n −1- 1).

Return true if it is possible to make the matrix disconnected after flipping at most one cell, or false otherwise.

Note: Flipping at most one cell means you can choose to flip 00 or 11 cell. A path is valid only if every cell visited has a value of 11.

Constraints:

  • m ==== grid.length

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

  • 1≤1 \leq m, n ≤1000\leq 1000

  • 1≤1 \leq m ×\times n ≤105\leq 10^5

  • grid[i][j] is either 00 or 11.

  • grid[0][0] ==== grid[m - 1][n - 1] ==1== 1

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Disconnect Path in a Binary Matrix by at Most One Flip

Try to solve the Disconnect Path in a Binary Matrix by at Most One Flip problem.

Statement

You are given a binary matrix grid of size m ×\times n.

From any cell (r,c)(r, c), you are permitted to move to (r+1,c)(r + 1, c) or (r,c+1)(r, c + 1) as long as the destination cell contains the value 11.

The matrix is disconnected if there is no valid path from the top left cell (0,0)(0, 0) to the bottom right cell (m −1- 1, n −1- 1).

You are allowed to flip the value of at most one cell from 11 to 00, excluding the cells (0,0)(0, 0) and (m −1- 1, n −1- 1).

Return true if it is possible to make the matrix disconnected after flipping at most one cell, or false otherwise.

Note: Flipping at most one cell means you can choose to flip 00 or 11 cell. A path is valid only if every cell visited has a value of 11.

Constraints:

  • m ==== grid.length

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

  • 1≤1 \leq m, n ≤1000\leq 1000

  • 1≤1 \leq m ×\times n ≤105\leq 10^5

  • grid[i][j] is either 00 or 11.

  • grid[0][0] ==== grid[m - 1][n - 1] ==1== 1