Tax the Largest Storage Bucket Each Day for K Days

Last updated: November 29, 2026

Quick Overview

Each day for k days, pick the storage bucket holding the most objects and shrink it to the floor of the square root of its size. Return the total number of objects left across all buckets.

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

0

0

0 solved


Each day for k days, pick the storage bucket holding the most objects and shrink it to the floor of the square root of its size. Return the total number of objects left across all buckets.

A quick Google screen simulation in a Cloud Storage cleanup frame. The interviewer wants the candidate to see that repeated access to the current maximum calls for a max-heap and to state the per-day cost.

What the Interviewer Expects
  • Uses a max-heap of bucket sizes
  • Applies integer square root correctly
  • Runs exactly k rounds
  • Sums the remaining sizes
  • States O(n + k log n)
Key Topics to Cover
Max-Heap
Simulation
Integer Math
Greedy
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 k is huge, like 10^9?
  • What if you need to report which bucket was taxed each day?
  • How would this change with a different shrink function?
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 integer bucket sizes and an integer k >= 0.
  • Each day: take the largest bucket (any one if tied) and replace its size x with floor(sqrt(x)).
  • Output: sum of all bucket size...
High-Level Design

The only state that matters each day is which bucket is largest, and that changes after every update, so keep a max-heap of sizes (stored negated). Each day pop the largest, compute isqrt, push the ...


Submit Your Answer
Markdown supported