Horizontal Line Bisecting Total Square Area
Problem statement
Each axis-aligned square is [topLeftX,topLeftY,side] and spans vertically from topLeftY-side to topLeftY.
Return the y-coordinate of a horizontal line for which the sum of square areas below the line equals the sum above it. Overlapping areas are counted once per square. Return the smallest valid coordinate when an interval of answers exists.
Function
horizontalBisector(squares: int[][]) → doubleExamples
Example 1
squares = [[1,2,5],[2,4,10]]return = -0.8333333333333335A sweep accounts for the changing total horizontal width; a weighted-center average is not generally an area bisector.
Example 2
squares = [[0,2,2]]return = 1A single square is bisected halfway between y=0 and y=2.
Example 3
squares = []return = 0The empty input uses coordinate zero.
Constraints
0 <= squares.length <= 100000.1 <= side <= 10^9.- An absolute error of
10^-6is accepted.