PracHub
QuestionsLearningGuidesInterview Prep
|Home/Coding & Algorithms/Google

Find a Horizontal Cut That Bisects Rectangle Area

Last updated: Jul 22, 2026

Quick Overview

Solve a computational-geometry problem that asks for the horizontal line dividing the combined area of many disjoint rectangles in half. The exercise emphasizes numerical precision, large coordinate ranges, performance at 200,000 rectangles, and careful treatment of partially intersected shapes.

  • medium
  • Google
  • Coding & Algorithms
  • Software Engineer

Find a Horizontal Cut That Bisects Rectangle Area

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

# Find a Horizontal Cut That Bisects Rectangle Area Several non-overlapping rectangular cakes lie on a plane. A cake is represented by `[x, y, width, height]`, where `(x, y)` is its lower-left corner. Find the height of a horizontal line `y = k` such that the total cake area strictly below the line equals the total cake area strictly above it. Cake material crossed by the line is split between the two sides. ```python def horizontal_bisector(rectangles: list[list[float]]) -> float: ... ``` The input guarantees a unique answer. Return `k`; an absolute or relative error of at most `1e-6` is accepted. The rectangles can be very far apart, so an approach whose range depends on a small board dimension is not appropriate. ## Constraints - `1 <= len(rectangles) <= 200_000` - `-10^9 <= x, y <= 10^9` - `0 < width, height <= 10^9` - Rectangles have disjoint interiors. - All input numbers are finite. ## Examples ```text Input: rectangles = [[0, 0, 4, 2]] Output: 1.0 ``` ```text Input: rectangles = [[0, 0, 2, 4], [10, 1, 2, 2]] Output: 2.0 Explanation: At y = 2, the first cake contributes area 4 below the line and the second contributes area 2 below it. The total area is 12, so both sides contain area 6. ```

Quick Answer: Solve a computational-geometry problem that asks for the horizontal line dividing the combined area of many disjoint rectangles in half. The exercise emphasizes numerical precision, large coordinate ranges, performance at 200,000 rectangles, and careful treatment of partially intersected shapes.

Related Interview Questions

  • Count Overlapping Rectangle Updates on a Grid - Google (hard)
  • Find A Threshold-Limited Path With Minimum Required Safety - Google (medium)
  • Filter Repeated Robot Status Messages - Google (medium)
  • Minimize Direction Violations in a Directed Road Network - Google (medium)
  • Find the Largest Monotone Increasing Number - Google (medium)
|Home/Coding & Algorithms/Google

Find a Horizontal Cut That Bisects Rectangle Area

Google logo
Google
Jun 4, 2026, 12:00 AM
mediumSoftware EngineerTechnical ScreenCoding & Algorithms
2
0

Find a Horizontal Cut That Bisects Rectangle Area

Several non-overlapping rectangular cakes lie on a plane. A cake is represented by [x, y, width, height], where (x, y) is its lower-left corner. Find the height of a horizontal line y = k such that the total cake area strictly below the line equals the total cake area strictly above it. Cake material crossed by the line is split between the two sides.

def horizontal_bisector(rectangles: list[list[float]]) -> float:
    ...

The input guarantees a unique answer. Return k; an absolute or relative error of at most 1e-6 is accepted. The rectangles can be very far apart, so an approach whose range depends on a small board dimension is not appropriate.

Constraints

  • 1 <= len(rectangles) <= 200_000
  • -10^9 <= x, y <= 10^9
  • 0 < width, height <= 10^9
  • Rectangles have disjoint interiors.
  • All input numbers are finite.

Examples

Input: rectangles = [[0, 0, 4, 2]]
Output: 1.0
Input: rectangles = [[0, 0, 2, 4], [10, 1, 2, 2]]
Output: 2.0

Explanation: At y = 2, the first cake contributes area 4 below the line and
the second contributes area 2 below it. The total area is 12, so both sides
contain area 6.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Google•More Software Engineer•Google Software Engineer•Google Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.