Dsa
Dynamic Programming
Hard
Maximal Square in Binary Matrix
Given a binary matrix filled with 0s and 1s, find the largest square containing only 1s and return its area.
Input format:
- The first line contains integers m and n (1 <= m, n <= 100).
- Each of the next m lines contains a binary string of length n.
Output format:
- Print a single integer representing the area of the largest square.
Example:
Input:
4 5
1 0 1 0 0
1 0 1 1 1
1 1 1 1 1
1 0 0 1 0
Output:
4
Key concepts
dynamic_programmingmatrix
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now