Back to problems

Maximal Square (LeetCode 221)

Algorithm · Salesforce · Hard

You are given an $$m \times n$$ binary grid where each cell contains either '0' or '1'. Your task is to locate the largest square submatrix composed entirely of '1' characters and return its area. A submatrix is square when its width equals its height, and every cell inside it is '1'. The side length of such a square is the number of cells along one edge. You must solve this by formulating a dynamic‑programming recurrence. Before coding, define the meaning of your DP state…

Checking your access…