|
| 1 | +<p>You are given a 2D integer array <code>squares</code>. Each <code>squares[i] = [x<sub>i</sub>, y<sub>i</sub>, l<sub>i</sub>]</code> represents the coordinates of the bottom-left point and the side length of a square parallel to the x-axis.</p> |
| 2 | + |
| 3 | +<p>Find the <strong>minimum</strong> y-coordinate value of a horizontal line such that the total area of the squares above the line <em>equals</em> the total area of the squares below the line.</p> |
| 4 | + |
| 5 | +<p>Answers within <code>10<sup>-5</sup></code> of the actual answer will be accepted.</p> |
| 6 | + |
| 7 | +<p><strong>Note</strong>: Squares <strong>may</strong> overlap. Overlapping areas should be counted <strong>multiple times</strong>.</p> |
| 8 | + |
| 9 | +<p> </p> |
| 10 | +<p><strong class="example">Example 1:</strong></p> |
| 11 | + |
| 12 | +<div class="example-block"> |
| 13 | +<p><strong>Input:</strong> <span class="example-io">squares = [[0,0,1],[2,2,1]]</span></p> |
| 14 | + |
| 15 | +<p><strong>Output:</strong> <span class="example-io">1.00000</span></p> |
| 16 | + |
| 17 | +<p><strong>Explanation:</strong></p> |
| 18 | + |
| 19 | +<p><img alt="" src="https://assets.leetcode.com/uploads/2025/01/06/4062example1drawio.png" style="width: 378px; height: 352px;" /></p> |
| 20 | + |
| 21 | +<p>Any horizontal line between <code>y = 1</code> and <code>y = 2</code> will have 1 square unit above it and 1 square unit below it. The lowest option is 1.</p> |
| 22 | +</div> |
| 23 | + |
| 24 | +<p><strong class="example">Example 2:</strong></p> |
| 25 | + |
| 26 | +<div class="example-block"> |
| 27 | +<p><strong>Input:</strong> <span class="example-io">squares = [[0,0,2],[1,1,1]]</span></p> |
| 28 | + |
| 29 | +<p><strong>Output:</strong> <span class="example-io">1.16667</span></p> |
| 30 | + |
| 31 | +<p><strong>Explanation:</strong></p> |
| 32 | + |
| 33 | +<p><img alt="" src="https://assets.leetcode.com/uploads/2025/01/15/4062example2drawio.png" style="width: 378px; height: 352px;" /></p> |
| 34 | + |
| 35 | +<p>The areas are:</p> |
| 36 | + |
| 37 | +<ul> |
| 38 | + <li>Below the line: <code>7/6 * 2 (Red) + 1/6 (Blue) = 15/6 = 2.5</code>.</li> |
| 39 | + <li>Above the line: <code>5/6 * 2 (Red) + 5/6 (Blue) = 15/6 = 2.5</code>.</li> |
| 40 | +</ul> |
| 41 | + |
| 42 | +<p>Since the areas above and below the line are equal, the output is <code>7/6 = 1.16667</code>.</p> |
| 43 | +</div> |
| 44 | + |
| 45 | +<p> </p> |
| 46 | +<p><strong>Constraints:</strong></p> |
| 47 | + |
| 48 | +<ul> |
| 49 | + <li><code>1 <= squares.length <= 5 * 10<sup>4</sup></code></li> |
| 50 | + <li><code>squares[i] = [x<sub>i</sub>, y<sub>i</sub>, l<sub>i</sub>]</code></li> |
| 51 | + <li><code>squares[i].length == 3</code></li> |
| 52 | + <li><code>0 <= x<sub>i</sub>, y<sub>i</sub> <= 10<sup>9</sup></code></li> |
| 53 | + <li><code>1 <= l<sub>i</sub> <= 10<sup>9</sup></code></li> |
| 54 | + <li>The total area of all the squares will not exceed <code>10<sup>12</sup></code>.</li> |
| 55 | +</ul> |
0 commit comments