1223. Largest Plus Sign

MediumDynamic Programming2D DP

In an n x n grid of 1s, the cells listed in mines are 0. A plus sign of order k centered at a cell has four arms of length k-1 (up, down, left, right) plus the center, all consisting of 1s. Return the order of the largest plus sign in the grid, or 0 if none exists. The input is JSON {n, mines}.

Input: JSON {n, mines}.

Output: Integer — the order of the largest plus sign.

Examples

Example 1
Input: {"n":5,"mines":[[4,2]]}
Output: 2
Explanation: A plus of order 2 fits.
Example 2
Input: {"n":1,"mines":[[0,0]]}
Output: 0
Explanation: The only cell is a mine.
Example 3
Input: {"n":1,"mines":[]}
Output: 1
Explanation: Order 1 at the single cell.

Constraints

Asked by

Meta
Solve this problem in the editor →