Trains the technique from
LeetCode 3453Separate Squares IThis 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.
Squares are given as squares, where squares[i] = [x, y, side] places a square with its bottom-left corner at (x, y) and its sides of length side parallel to the axes. Squares may overlap, and an overlapping patch counts once for every square covering it.
Find the smallest height h such that the horizontal line at that height leaves as much square area below it as above it, and return h.
An answer within 10^-5 of the true one is accepted.
Example 1
Two squares of area four stand one on top of the other, so the line has to leave four below it, which is exactly the join between them.
Example 2
The areas are four and one, so the line must leave two and a half below it. Above height one both squares straddle the line, and their widths of two and one together raise the area below by three for every unit of height, so half is reached a sixth of the way up.
Example 3
Each square has area one, so the line must leave one below it. The lower square finishes at height one, and nothing else is painted until height three, so one is the smallest height that works.
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 separate_squares(squares: list[list[int]]) -> float:public double separateSquares(int[][] squares)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.