Problem · Array

Largest Plus Sign

Learn this problem
MediumxAI logoxAIFULLTIMEOA

Problem statement

You have an n x n binary grid initially filled with ones. Every coordinate in mines is changed to zero.

An axis-aligned plus sign of order k has a center cell and four arms of ones extending k - 1 cells up, down, left, and right. Return the largest possible order. Return 0 if the grid contains no one.

Function

orderOfLargestPlusSign(n: int, mines: int[][]) → int

Examples

Example 1

n = 5mines = [[4,2]]return = 2

A plus centered at [2,2] has one cell in each arm, so its order is 2.

Example 2

n = 1mines = [[0,0]]return = 0

The only cell is zero.

Constraints

  • 1 <= n <= 500.
  • 0 <= mines.length <= n * n.
  • Every mine is a distinct pair [row, col] with 0 <= row, col < n.

More xAI problems

drafts saved locally
public int orderOfLargestPlusSign(int n, int[][] mines) {
    // Write your code here.
}
n5
mines[[4,2]]
expected2
checking account