Ctrl K

Widest Cross in a Minefield

Medium
The field is a size × size square. Every cell is clear except the mined ones: each pair [r, c] in mines puts a mine at row r, column c. A **cross of order k** is a clear center cell plus four arms of clear cells, each of length k - 1, going up, down, left and right. A cross of order 1 is a single clear cell. Whatever lies beyond the ends of the arms does not matter. Return the order of the largest cross that fits on the field, or 0 if there are no clear cells.
Example 1
size=5, mines=[[0, 0], [4, 1]] → 3

Centered at (2, 2), all four arms of length 2 are clear (the mines at (0, 0) and (4, 1) are off the arms). That is a cross of order 3, the most a 5×5 field allows.

Example 2
size=2, mines=[[0, 0], [1, 1]] → 1

Only (0, 1) and (1, 0) are free, and each is next to an edge or a mine, so only a cross of order 1 fits.

Example 3
size=1, mines=[[0, 0]] → 0

The only cell holds a mine, so there is no cross and the answer is 0.

Constraints
  • 1 ≤ size ≤ 500
  • 0 ≤ len(mines) ≤ 5000
  • 0 ≤ r, c < size
  • All pairs in mines are distinct
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsFewest Jumps to the End MediumMost Profitable Streak MediumReach the Last Cell MediumWarehouse Cart Routes MediumCheapest Corner-to-Corner Route Medium
loading Python…
Input
size=5, mines=[[0, 0], [4, 1]]
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 91 tests on the server, hidden ones included.