🎨 The ART of Dynamic Programming
\uD83C\uDFA8 The ART of Dynamic Programming: Use prefix sums to track the length of continuous 1s from all four cardinal directions: up, down, left, right.  The
[\uD83C\uDFA8 The ART of Dynamic Programming:](https://leetcode.com/discuss/general-discussion/712010/The-ART-of-Dynamic-Programming-An-Intuitive-Approach%3A-from-Apprentice-to-Master) Use prefix sums to track the length of continuous 1s from all four cardinal directions: up, down, left, right.  Then perform a scan of the board cell\'s `i`, `j` to find and return the maximum of each cell\'s minimum length of continuous 1s of all four cardinal directions as the `best` answer.\n\n---\n\n*Kotlin*\n```\nclass Solution {\n    fun orderOfLargestPlusSign(N: Int, X: Array<IntArray>): Int {\n        var A = Array<IntArray>(N) { IntArray(N) { 1 } }\n        for ((i, j) in X)\n            A[i][j] = 0\n        var (U, D, L, R) = Array(4) { A.map{ it.copyOf() } }\n        for (i in 1 until N - 1) {\n            for (j in 1 until N - 1) {\n                var u = N - 1 - i\n                var v = N - 1 - j\n                if (A[i][j] == 1) {\n                    U[i][j] = 1 + U[i - 1][j]\n                    L[i][j] = 1 + L[i][j - 1]\n                }\n                if (A[u][v] == 1) {\n                    D[u][v] = 1 + D[u + 1][v]\n                    R[u][v] = 1 + R[u][v + 1]\n                }\n            }\n        }\n        return Array(N){ IntArray(N){ it } }.mapIndexed{ i, row -> row.map{ j -> listOf(U[i][j], D[i][j], L[i][j], R[i][j]).min()!! }.max()!! }.max()!!\n    }\n}\n```\n\n*Javascript*\n```\nlet orderOfLargestPlusSign = (N, X, best = 0) => {\n    let A = [...Array(N)].map(_ => Array(N).fill(1));\n    for (let [i, j] of X)\n        A[i][j] = 0;\n    let [U, D, L, R] = [...Array(4)].map(_ => A.map(row => [...row]));\n    for (let i = 1; i < N - 1; ++i) {\n        for (let j = 1; j < N - 1; ++j) {\n            let u = N - 1 - i,\n                v = N - 1 - j;\n            if (A[i][j]) {\n                U[i][j] = 1 + U[i - 1][j];\n                L[i][j] = 1 + L[i][j - 1];\n            }\n            if (A[u][v]) {\n                D[u][v] = 1 + D[u + 1][v];\n                R[u][v] = 1 + R[u][v + 1];\n            }\n        }\n    }\n    return Math.max(...[...Array(N).keys()].map(i => Math.max(...[...Array(N).keys()].map(j => Math.min(U[i][j], D[i][j], L[i][j], R[i][j])))));\n};\n```\n\n*Python3*\n```\nclass Solution:\n    def orderOfLargestPlusSign(self, N: int, X: List[List[int]], best = 0) -> int:\n        A = [N * [1] for _ in range(N)]\n        for i, j in X:\n            A[i][j] = 0\n        U, D, L, R = [[row[:] for row in A] for _ in range(4)]\n        for i in range(1, N - 1):\n            for j in range(1, N - 1):\n                u = N - 1 - i\n                v = N - 1 - j\n                if A[i][j]:\n                    U[i][j] = 1 + U[i - 1][j]\n                    L[i][j] = 1 + L[i][j - 1]\n                if A[u][v]:\n                    D[u][v] = 1 + D[u + 1][v]\n                    R[u][v] = 1 + R[u][v + 1]\n        return max(min(U[i][j], D[i][j], L[i][j], R[i][j]) for j in range(N) for i in range(N))\n```\n\n*C++*\n```\nclass Solution {\npublic:\n    using VI = vector<int>;\n    using VVI = vector<VI>;\n    int orderOfLargestPlusSign(int N, VVI& X, int best = 0) {\n        VVI A(N, VI(N, 1));\n        for (auto& x: X) {\n            auto [i, j] = tie(x[0], x[1]);\n            A[i][j] = 0;\n        }\n        VVI U{ A }, D{ A }, L{ A }, R{ A };\n        for (auto i{ 1 }; i < N - 1; ++i) {\n            for (auto j{ 1 }; j < N - 1; ++j) {\n                auto u = N - 1 - i,\n                     v = N - 1 - j;\n                if (A[i][j]) {\n                    U[i][j] = 1 + U[i - 1][j];\n                    L[i][j] = 1 + L[i][j - 1];\n                }\n                if (A[u][v]) {\n                    D[u][v] = 1 + D[u + 1][v];\n                    R[u][v] = 1 + R[u][v + 1];\n                }\n            }\n        }\n        for (auto i{ 0 }; i < N; ++i)\n            for (auto j{ 0 }; j < N; ++j)\n                best = max(best, min({ U[i][j], D[i][j], L[i][j], R[i][j] }));\n        return best;\n    }\n};\n```\n
[]