Fewest Halvings to Cut Total Cloud Spend in Half

Last updated: November 29, 2026

Quick Overview

Each project has a monthly cloud cost. One operation halves any single project's current cost (it can be halved again later). Return the minimum number of operations needed to reduce the total cost by at least half.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Each project has a monthly cloud cost. One operation halves any single project's current cost (it can be halved again later). Return the minimum number of operations needed to reduce the total cost by at least half.

A Google technical-screen greedy question set in a Cloud billing optimization frame. The interviewer wants the greedy of always halving the current largest cost and a convincing reason why it is optimal.

What the Interviewer Expects
  • Identifies halving the current maximum as the greedy
  • Justifies the greedy with an exchange argument
  • Uses a max-heap of floats
  • Tracks the reduction until it reaches half the original total
  • States O(n + ops log n)
Key Topics to Cover
Max-Heap
Greedy
Floating Point
Optimization
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
  • What if each halving has a per-project fee?
  • What if a project can be halved at most twice?
  • How many operations can this take in the worst case?
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 positive numbers.
  • One op: replace some value x with x / 2.
  • Goal: total reduced by at least sum / 2.
  • Output: the minimum number of ops....
High-Level Design

Halving x removes x / 2 from the total, so the biggest single gain always comes from halving the current largest value. Greedy argument: any solution that halves a smaller value y at some step while x...


Submit Your Answer
Markdown supported