#764

Largest Plus Sign

specialist · 895 · lc medium +31 · verified · 49.1% accepted · 1,536 likes · top 35%

Description

You have an n x n binary grid initially filled with 1s, except for cells listed in mines (each entry [xi, yi] marks grid[xi][yi] = 0). An axis-aligned plus sign of order k centered at grid[r][c] requires that grid[r][c] and all k - 1 cells extending in each of the four cardinal directions are 1.

Return the order of the largest such plus sign in the grid, or 0 if none exists.

Example 1:

Input: n = 5, mines = [[4,2]]
Output: 2
Explanation: In the above grid, the largest plus sign can only be of order 2. One of them is shown.

Example 2:

Input: n = 1, mines = [[0,0]]
Output: 0
Explanation: There is no plus sign, so return 0.

Code

1
2
3