Horizontal Line Bisecting Total Square Area
Updated
Problem statement
Each axis-aligned square is [topLeftX,topLeftY,side] and spans vertically from topLeftY-side to topLeftY.
Return the y-coordinate of a horizontal line for which the sum of square areas below the line equals the sum above it. Overlapping areas are counted once per square. Return the smallest valid coordinate when an interval of answers exists.
Function
horizontalBisector(squares: int[][]) → doubleExamples
Example 1
squares = [[1,2,5],[2,4,10]]return = -0.8333333333333335A sweep accounts for the changing total horizontal width; a weighted-center average is not generally an area bisector.
Example 2
squares = [[0,2,2]]return = 1A single square is bisected halfway between y=0 and y=2.
Example 3
squares = []return = 0The empty input uses coordinate zero.
Constraints
0 <= squares.length <= 100000.1 <= side <= 10^9.- An absolute error of
10^-6is accepted.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Merge Collinear Point SegmentsApplied Intuition · PHONE SCREEN
- Highlight and Rank Overlapping CitationsHarvey · PHONE SCREEN · ONSITE INTERVIEW
- Light Source Hits: Sample, Compare, and FitOpenAI · PHONE SCREEN
- Worker Management with Promotions and Double-Paid TimeInstacart · ONSITE INTERVIEW
- Maximum Profit in Job SchedulingAmazon · PHONE SCREEN
- Lab and Consultation Appointment MatchingAssort Health · PHONE SCREEN
- Closest Pair of PointsCitadel · PHONE SCREEN
- Employee Free TimeIDFC Bank · ONSITE INTERVIEW
- Maximum Visible DronesAnduril · PHONE SCREEN
- Fewest Days Until a Point Holds k VariantsAdobe · PHONE SCREEN