Largest Plus Sign - Problem
The Plus Sign Mining Challenge

Imagine you're a mining engineer surveying a n × n grid of land for the perfect spot to build a plus-shaped mining facility. The entire grid is initially suitable for construction (all 1's), but some locations have been marked as unusable due to mines (0's).

Your goal is to find the largest possible plus sign that can be built on this grid. A plus sign of order k has:
• A center point with value 1
• Four arms extending in cardinal directions (up, down, left, right)
• Each arm has exactly k-1 consecutive 1's

For example, a plus sign of order 3 looks like:
  1
1
1 1 1
1
1

Return the order of the largest plus sign you can construct, or 0 if no plus sign is possible.

Input & Output

example_1.py — Basic Case
$ Input: n = 5, mines = [[4, 2]]
Output: 2
💡 Note: In a 5×5 grid with one mine at position [4,2], the largest plus sign has order 2. It can be centered at positions like [2,2] with arms extending 1 cell in each direction.
example_2.py — No Mines
$ Input: n = 1, mines = []
Output: 1
💡 Note: A 1×1 grid with no mines can form a plus sign of order 1 (just the center cell itself).
example_3.py — All Mines
$ Input: n = 2, mines = [[0,0],[0,1],[1,0],[1,1]]
Output: 0
💡 Note: When all cells are mines, no plus sign can be formed, so the answer is 0.

Time & Space Complexity

Time Complexity
⏱️
O(n³)

For each of n² cells, we potentially check O(n) cells in each direction

n
2n
Quadratic Growth
Space Complexity
O(1)

Only using constant extra space for variables

n
2n
Linear Space

Constraints

  • 1 ≤ n ≤ 500
  • 1 ≤ mines.length ≤ 5000
  • 0 ≤ xi, yi < n
  • All the pairs (xi, yi) are unique
Asked in
25.0K Views
Medium Frequency
~15 min Avg. Time
850 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen