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.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

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
Prefix Sums
Arrays
Running Total
Balance Index
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample Answer
Requirements
  • Input: list of integers counts (I will allow negatives for generality, though real counts are non-negative).
  • Output: smallest i such that sum(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 ...


Submit Your Answer
Markdown supported