Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Maximal Square

XPChallenge Points: 20
levelLevel: Medium

You are given a 2-D grid of size m × n containing only "0" and "1".
Find the largest square made up of only "1" cells and return its area (number of cells inside that square).

Example 1:

Input: matrix = [ ["1","0","1","0","0"], ["1","1","1","1","0"], ["1","1","1","1","1"], ["0","1","1","1","0"] ]

Output: 4

Explanation:

The biggest square of all 1s has side length 2, so area = 2×2 = 4.

Example 2:

Input: matrix = [ ["0","1"], ["1","1"] ]

Output: 1

Explanation:

The largest square of only 1s has side length 1, so area = 1.

Example 3:

Input: matrix = [ ["0"] ]

Output: 0

Explanation:

No 1s are present, so the area is 0.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result