17.23. Max Black Square
Description
Imagine you have a square matrix, where each cell (pixel) is either black or white Design an algorithm to find the maximum subsquare such that all four borders are filled with black pixels.
Return an array [r, c, size]
, where r
, c
are the row number and the column number of the subsquare's upper left corner respectively, and size
is the side length of the subsquare. If there are more than one answers, return the one that has smallest r
. If there are more than one answers that have the same r
, return the one that has smallest c
. If there's no answer, return an empty array.
Example 1:
Input: [ [1,0,1], [0,0,1], [0,0,1] ] Output: [1,0,2] Explanation: 0 represents black, and 1 represents white, bold elements in the input is the answer.
Example 2:
Input: [ [0,1,1], [1,0,1], [1,1,0] ] Output: [0,0,1]
Note:
matrix.length == matrix[0].length <= 200
Solutions
Solution 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|