| 4 | |
| 5 | public class Question { |
| 6 | public static Subsquare findSquareWithSize(int[][] matrix, int squareSize) { |
| 7 | // On an edge of length N, there are (N - sz + 1) squares of length sz. |
| 8 | int count = matrix.length - squareSize + 1; |
| 9 | |
| 10 | // Iterate through all squares with side length square_size. |
| 11 | for (int row = 0; row < count; row++) { |
| 12 | for (int col = 0; col < count; col++) { |
| 13 | if (isSquare(matrix, row, col, squareSize)) { |
| 14 | return new Subsquare(row, col, squareSize); |
| 15 | } |
| 16 | } |
| 17 | } |
| 18 | return null; |
| 19 | } |
| 20 | |
| 21 | public static Subsquare findSquare(int[][] matrix){ |
| 22 | assert(matrix.length > 0); |