public static ArrayList<Square> findLargestSubsquare2(int[][] matrix) {
        if (matrix == null) return null;
        Cell[][] cells = preprocess(matrix);
        ArrayList<Square> result = new ArrayList<Square>();
        for (int size = cells.length; size >= 1; --size) {
            for (int i = 0; i < cells.length - size + 1; ++i) {
                for (int j = 0; j < cells[0].length - size + 1; ++j) {
                    if (isValid(cells, i, j, size)) {
                        result.add(new Square(i, j, size));
                    }
                }
            }
            if (!result.isEmpty()) break;
        }
        return result;
    }