Code RoomCount all-ones square submatrices
MediumPrep Room Coding #90

Count all-ones square submatrices

CodingAlgorithms & data structuresMid–Senior~20 min

Given an m x n binary matrix (entries are 0 or 1), count how many square submatrices have all entries equal to 1. Squares of every side length count, and squares overlapping each other are counted separately. Return the total number of all-ones square submatrices. Dimensions are at least 1x1 and at most 300x300.

Implement
count_squares(matrix: list[list[int]]) → int
Examples
in[[[0,1,1,1],[1,1,1,1],[0,1,1,1]]]out15
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 20 min
InputExpectedGot
[[[0,1,1,1],[1,1,1,1],[0,1,1,1]]]15not run yetsample