Trains the technique from
LeetCode 4016Maximum Area of Two Non-Overlapping Square SubmatricesThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A panel is given as mat, each cell holding 0 or 1. A cell holding 1 is sound.
Find two squares of sound cells, both the same size, that do not overlap each other, choosing the largest size for which two such squares exist. Return the total area they cover, which is twice the square of that size, or 0 when no two squares of any size fit.
Example 1
Two squares of side two fit side by side in the four columns without overlapping, covering eight cells between them. No larger size fits at all on a panel two rows deep.
Example 2
Two single sound cells sit apart from each other, covering two cells.
Example 3
There is only one sound cell, so no two squares fit.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def max_area(mat: list[list[int]]) -> int:public int maxArea(int[][] mat)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.