ORIGINAL CODING QUESTION
Largest solid square area
Return the area of the largest axis-aligned square containing only one cells, or 0 when no land exists.
Original exercise · medium. Editorial role relevance does not imply a company has asked this question.
Input and output
rows cols, then rows×cols cell values in row-major order. Print one integer.
Constraints
1 ≤ rows,cols ≤ 12; each cell is 0 or 1; adjacency uses four sides, not diagonals.
Example 1
Input
2 3 1 1 0 1 1 1
Output
4
The left 2×2 square has area 4.
Example 2
Input
2 2 1 0 0 1
Output
1
Only singleton squares qualify.
Explain your approach
Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?
Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.
Hint 1
A square ending here extends squares above, left and diagonally above-left.
Hint 2
The smallest of those three sizes limits growth.
Hint 3
Track side lengths, then square the largest side.
Practice this question
Save your work privately, explain decisions and return to your revision queue.
Open practice workspaceBrowse the question library →