Question bank › Dynamic Programming
Dsa Dynamic Programming Medium

Maximal Square in Binary Grid

Given a binary grid (a 2D array of 0s and 1s), write a program to return the area of the largest square containing only 1s. Input format: - The first line contains two integers 'm' and 'n' (1 <= m,n <= 100), the dimensions of the grid. - The next 'm' lines each contain 'n' space-separated integers, either 0 or 1, representing the binary grid. Output format: - A single integer representing the area of the largest square. Example: Input: 3 4 1 0 1 0 1 1 1 1 1 0 1 0 Output: 4 The largest square is formed by the four 1s in the second row and second column.

Key concepts

dynamic_programming2d_arraysmatrices

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.