FastPrepCenter of the Largest Diagonal X

Center of the Largest Diagonal X

ZipRecruiter logoZipRecruiter● MediumNEW GRADOA
Learn

Problem statement

An X of arm length k is centered on a cell containing 1 and contains 1 at every offset d from 0 through k - 1 in all four diagonal directions. Its bounding square has odd side length 2k - 1.

Return the center of an X with maximum arm length, breaking ties by row and then column. A single 1 has arm length one. Return [-1,-1] when the matrix contains no 1.

Function

largestXCenter(grid: int[][]) → int[]

Examples

Example 1

grid = [[1,0,1],[0,1,0],[1,0,1]]return = [1,1]

The center has arm length two.

Example 2

grid = [[0,0],[0,0]]return = [-1,-1]

A matrix without one returns the sentinel.

Constraints

  • 1 <= rows, columns <= 200
  • Every cell is 0 or 1.

More ZipRecruiter problems

See ZipRecruiter hiring insights
public int[] largestXCenter(int[][] grid) {
    // Write your code here.
}
grid[[1,0,1],[0,1,0],[1,0,1]]
expected[1,1]
Checking account…