3453. Separate Squares I Medium

@problem@discussion
#Array#Binary Search



1/**
2 * [3453] Separate Squares I
3 *
4 * 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.
5 * Find the minimum y-coordinate value of a horizontal line such that the total area of the squares above the line equals the total area of the squares below the line.
6 * Answers within 10^-5 of the actual answer will be accepted.
7 * Note: Squares may overlap. Overlapping areas should be counted multiple times.
8 *  
9 * <strong class="example">Example 1:
10 * <div class="example-block">
11 * Input: <span class="example-io">squares = [[0,0,1],[2,2,1]]</span>
12 * Output: <span class="example-io">1.00000</span>
13 * Explanation:
14 * <img alt="" src="https://assets.leetcode.com/uploads/2025/01/06/4062example1drawio.png" style="width: 378px; height: 352px;" />
15 * Any horizontal line between y = 1 and y = 2 will have 1 square unit above it and 1 square unit below it. The lowest option is 1.
16 * </div>
17 * <strong class="example">Example 2:
18 * <div class="example-block">
19 * Input: <span class="example-io">squares = [[0,0,2],[1,1,1]]</span>
20 * Output: <span class="example-io">1.16667</span>
21 * Explanation:
22 * <img alt="" src="https://assets.leetcode.com/uploads/2025/01/15/4062example2drawio.png" style="width: 378px; height: 352px;" />
23 * The areas are:
24 * 
25 * 	Below the line: 7/6 * 2 (Red) + 1/6 (Blue) = 15/6 = 2.5.
26 * 	Above the line: 5/6 * 2 (Red) + 5/6 (Blue) = 15/6 = 2.5.
27 * 
28 * Since the areas above and below the line are equal, the output is 7/6 = 1.16667.
29 * </div>
30 *  
31 * Constraints:
32 * 
33 * 	1 <= squares.length <= 5 * 10^4
34 * 	squares[i] = [xi, yi, li]
35 * 	squares[i].length == 3
36 * 	0 <= xi, yi <= 10^9
37 * 	1 <= li <= 10^9
38 * 	The total area of all the squares will not exceed 10^12.
39 * 
40 */
41pub struct Solution {}
42
43// problem: https://leetcode.com/problems/separate-squares-i/
44// discuss: https://leetcode.com/problems/separate-squares-i/discuss/?currentPage=1&orderBy=most_votes&query=
45
46// submission codes start here
47
48impl Solution {
49    pub fn separate_squares(squares: Vec<Vec<i32>>) -> f64 {
50        0f64
51    }
52}
53
54// submission codes end
55
56#[cfg(test)]
57mod tests {
58    use super::*;
59
60    #[test]
61    fn test_3453() {
62    }
63}
64

Back
© 2026 bowen.ge All Rights Reserved.