Center of the Largest Diagonal X
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.