Find the Balance Point in a Week of Hourly Request Counts
Last updated: November 29, 2026
Quick Overview
Given an array of hourly request counts, return the leftmost index where the sum of counts strictly to the left equals the sum strictly to the right, or -1 if no such index exists.
0
0
0 solved
Given an array of hourly request counts, return the leftmost index where the sum of counts strictly to the left equals the sum strictly to the right, or -1 if no such index exists.
Asked in the style of a Google phone screen, framed as finding where load splits evenly so a traffic window can be cut between two serving clusters. The interviewer is checking prefix-sum thinking and avoidance of the quadratic recomputation.
What the Interviewer Expects
- Avoids recomputing left and right sums for each index
- Uses total sum and a running left sum
- Gets the 'strictly left and right' boundary correct
- Returns the leftmost valid index
- Considers negative values and single-element arrays
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Return every balance index, not just the first.
- Split the array into three parts with equal sums; how many ways?
- How would you find the balance point when the data is spread across shards?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: list of integers
counts(I will allow negatives for generality, though real counts are non-negative). - Output: smallest
isuch thatsum(counts[:i]) == sum(counts[i+1:]), else -1. - For...
High-Level Design
Computing both sums for each index is O(n^2). Instead compute total once. While scanning, maintain left, the sum of elements before i. The right sum is then total - left - counts[i]. When the ...