Solution Largest 1-Bordered Square
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n\n    /**\n     * @param Integer[][] $grid\n     * @return Integer\n     */\n    function largest1BorderedSquare($grid) {\n        $m = count($grid);\n        $n = count($grid[0]);\n        $maxSize = 0;\n        \n        $horizontal = array_fill(0, $m, array_fill(0, $n, 0));\n        $vertical = array_fill(0, $m, array_fill(0, $n, 0));\n        \n        for ($i = 0; $i < $m; $i++) {\n            for ($j = 0; $j < $n; $j++) {\n                if ($grid[$i][$j] == 1) {\n                    $horizontal[$i][$j] = ($j == 0) ? 1 : $horizontal[$i][$j - 1] + 1;\n                    $vertical[$i][$j] = ($i == 0) ? 1 : $vertical[$i - 1][$j] + 1;\n                }\n            }\n        }\n        \n        for ($i = 0; $i < $m; $i++) {\n            for ($j = 0; $j < $n; $j++) {\n                $size = min($horizontal[$i][$j], $vertical[$i][$j]);\n                while ($size > $maxSize) {\n                    if ($horizontal[$i - $size + 1][$j] >= $size && $vertical[$i][$j - $size + 1] >= $size) {\n                        $maxSize = $size;\n                    }\n                    $size--;\n                }\n            }\n        }\n        \n        return $maxSize * $maxSize;\n    }\n}\n\n\n```
['PHP']