PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Google

Find where to cut cake into equal areas

Last updated: Mar 29, 2026

Quick Overview

This question evaluates geometric area computation, handling of piecewise-constant profiles formed by adjacent rectangles, and attention to numerical precision when partitioning contiguous segments.

  • medium
  • Google
  • Coding & Algorithms
  • Software Engineer

Find where to cut cake into equal areas

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

### Cut a cake so both sides have equal area A cake is made of **N** rectangular blocks arranged left-to-right in a straight line (no gaps, no overlap). Block `i` has: - width `w_i` - height `h_i` All blocks share the same baseline; the cake’s top edge forms a step-like profile. You want to make **one vertical cut** at position `x` (measured from the cake’s left edge) so that the **area to the left of the cut equals the area to the right**. #### Input - An integer `N`. - Arrays `w[0..N-1]`, `h[0..N-1]`. #### Output - Return the cut position `x` as a real number such that: - `0 <= x <= sum(w_i)` - area(left of `x`) = total_area / 2 #### Notes - If the cut falls inside a block, that block is split proportionally by width. - Assume `total_area` is even in the sense that an exact cut position exists. #### Complexity discussion Explain your approach and its time/space complexity. (A common approach is to search which block contains the half-area point, then locate the exact offset inside that block.)

Quick Answer: This question evaluates geometric area computation, handling of piecewise-constant profiles formed by adjacent rectangles, and attention to numerical precision when partitioning contiguous segments.

Related Interview Questions

  • Solve Rooms and Top-K Streams - Google (medium)
  • Find Containing Range - Google (medium)
  • Rearrange Tasks With Cooldown - Google (medium)
  • Implement Employee Management and Expression Evaluation - Google (medium)
  • Solve Three Array and Matrix Path Problems - Google (medium)
Google logo
Google
Jan 6, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
7
0
Loading...

Cut a cake so both sides have equal area

A cake is made of N rectangular blocks arranged left-to-right in a straight line (no gaps, no overlap). Block i has:

  • width w_i
  • height h_i

All blocks share the same baseline; the cake’s top edge forms a step-like profile.

You want to make one vertical cut at position x (measured from the cake’s left edge) so that the area to the left of the cut equals the area to the right.

Input

  • An integer N .
  • Arrays w[0..N-1] , h[0..N-1] .

Output

  • Return the cut position x as a real number such that:
    • 0 <= x <= sum(w_i)
    • area(left of x ) = total_area / 2

Notes

  • If the cut falls inside a block, that block is split proportionally by width.
  • Assume total_area is even in the sense that an exact cut position exists.

Complexity discussion

Explain your approach and its time/space complexity. (A common approach is to search which block contains the half-area point, then locate the exact offset inside that block.)

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,000+ real questions from top companies.

Product

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

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL 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.