Largest square of ones

Write codeMedium20 min

Your task

Given an m x n binary matrix whose entries are 0 or 1, find the largest square containing only 1s and return its area. If the matrix contains no 1s, return 0. The matrix has at least one cell and dimensions up to 300x300.

Examples

maximal_square(matrix: list[list[int]]) -> int
Example 1
Inputmaximal_square([[1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [1, 0, 0, 1, 0]])
Output4