Maximal Square

TopicDifficultyCompanies
Dynamic Programming
MEDIUM
Google
Microsoft

You are given a 2D binary matrix arr[][] filled with 0's and 1's. The array contains a square of 1's. So, you need to find that square and return its area.

Example 1

Input: 
1 1 1 1 0
1 1 1 1 1
1 1 1 1 1
1 0 1 0 0

Output: 9
Explanation: The largest square in the given matrix has an area of 9 sq. units.

Example 2

Input: 
0 0 0 0 1 1
0 1 1 1 1 0
0 1 1 1 1 0
0 1 1 1 1 0
1 1 1 1 1 1
1 0 0 0 0 0
Output: 16
Explanation: The largest square in the given matrix has an area of 16 sq. units.

Code Editor

Practice and Learn

Best way to learn is through solving real problems. Practice this problem in this code editor.