Please solve the programming task below using a self-contained code snippet in a markdown code block.

Given a 2D grid of 0s and 1s, return the number of elements in the largest square subgrid that has all 1s on its border, or 0 if such a subgrid doesn't exist in the grid.
 
Please complete the following python code precisely:
```python
class Solution:
    def largest1BorderedSquare(self, grid: List[List[int]]) -> int:
```