sheet with m rows and n columns: "1" is an inked cell and "0" is a clean one. All inked cells form a single blot: you can get from any inked cell to any other by stepping up, down, left or right over inked cells.
You know one cell of the blot, (row, col). Return the area of the smallest rectangle aligned with the rows and columns that covers the whole blot.
Scanning every cell is the obvious way; try to beat O(m · n).sheet=[["0", "1", "1"], ["0", "1", "0"], ["1", "1", "0"]], row=0, col=1 → 9
The blot spans rows 0 to 2 and columns 0 to 2, so the frame is 3 × 3 = 9.
sheet=[["0", "0", "0"], ["0", "1", "1"]], row=1, col=2 → 2
The blot is two cells in a single row, a 1 × 2 frame.
sheet=[["1"]], row=0, col=0 → 1
m, n ≤ 100"0" or "1"row < m, 0 ≤ col < n, and sheet[row][col] = "1"sheet=[["0", "1", "1"], ["0", "1", "0"], ["1", "1", "0"]], row=0, col=1
9
Run checks the first 3 tests in your browser. Submit checks all 47 tests on the server, hidden ones included.