<p>Given a 2D <code>grid</code> of <code>0</code>s and <code>1</code>s, return the number of elements in&nbsp;the largest <strong>square</strong>&nbsp;subgrid that has all <code>1</code>s on its <strong>border</strong>, or <code>0</code> if such a subgrid&nbsp;doesn&#39;t exist in the <code>grid</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> grid = [[1,1,1],[1,0,1],[1,1,1]]
<strong>Output:</strong> 9
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> grid = [[1,1,0,0]]
<strong>Output:</strong> 1
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= grid.length &lt;= 100</code></li>
	<li><code>1 &lt;= grid[0].length &lt;= 100</code></li>
	<li><code>grid[i][j]</code> is <code>0</code> or <code>1</code></li>
</ul>
class Solution:
    def largest1BorderedSquare(self, grid: List[List[int]]) -> int:
        def checkSquare(r, c, size):
            for i in range(r, r + size):
                if grid[i][c] != 1 or grid[i][c + size - 1] != 1:
                    return False
            for j in range(c, c + size):
                if grid[r][j] != 1 or grid[r + size - 1][j] != 1:
                    return False
            return True
        
        row_count, col_count = len(grid), len(grid[0])
        largest = 0
        for size in range(1, min(row_count, col_count) + 1):
            for r in range(row_count - size + 1):
                for c in range(col_count - size + 1):
                    if checkSquare(r, c, size):
                        largest = max(largest, size * size)
        return largest
17000