Skip to interview prep
Apexed
Problem list107 / 125

107. Largest Square of 1s

MediumDynamic programming

matrix contains only 0s and 1s (as numbers). Return the area of the largest square sub-matrix made entirely of 1s.

Example 1

Input: matrix = [[1,0,1,0,0],[1,0,1,1,1],[1,1,1,1,1],[1,0,0,1,0]]
Output: 4

Constraints

  • 1 ≤ rows, cols ≤ 300

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 5 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

Largest Square of 1s — coding interview practice — Apexed