Separate Squares II

You are given a 2D integer array squares. Each squares[i] = [xi, yi, li] represents the coordinates of the bottom-left point and the side length of a square parallel to the x-axis.

Find the minimum y-coordinate value of a horizontal line such that the total area covered by squares above the line equals the total area covered by squares below the line.

Answers within 10^-5 of the actual answer will be accepted.

Note: Squares may overlap. Overlapping areas should be counted only once in this version.

Example 1
Inputsquares = [[0,0,1],[2,2,1]]
Output1
Any horizontal line between y = 1 and y = 2 results in an equal split, with 1 square unit above and 1 square unit below, so the minimum y-value is 1.
Example 2
Inputsquares = [[0,0,2],[1,1,1]]
Output1
Since the blue square overlaps with the red square, it is not counted again, and the line y = 1 splits the squares into two equal parts.

Constraints

  • 1 <= squares.length <= 5 * 10^4
  • squares[i] = [xi, yi, li]
  • squares[i].length == 3
  • 0 <= xi, yi <= 10^9
  • 1 <= li <= 10^9
  • The total area of all the squares will not exceed 10^15.

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate