Minimize Remaining Inventory After Halving the Largest Bin K Times

Last updated: November 29, 2026

Quick Overview

Each warehouse bin holds a number of units. A clearance operation removes floor(units / 2) from one chosen bin. Apply exactly k operations (the same bin may be chosen again) and return the minimum possible total units left.

Amazon
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Easy

0

0

0 solved


Each warehouse bin holds a number of units. A clearance operation removes floor(units / 2) from one chosen bin. Apply exactly k operations (the same bin may be chosen again) and return the minimum possible total units left.

A quick heap greedy item typical of Amazon's online assessment, framed as a clearance sale that empties half of a bin per action. Interviewers verify you pick the largest bin every time and use a heap rather than re-sorting.

What the Interviewer Expects
  • Observe that the largest bin yields the biggest removal
  • Use a max-heap and apply k pops and pushes
  • Use integer floor division correctly
  • Track the total incrementally
  • State O(n + k log n) time
Key Topics to Cover
heaps
greedy
priority queue
simulation
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 operation removed a fixed fraction p instead of half?
  • How would you handle k up to 10^9 when bins quickly become 1 unit?
  • What if operations had different costs per bin?
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

Inputs: list of positive integers piles and integer k >= 0. Output: minimum total after k operations, each replacing x with x - floor(x / 2) for one chosen pile....

High-Level Design

Removing floor(x / 2) is non-decreasing in x, so the biggest pile always gives the largest single-step reduction, and choosing it never hurts future steps because piles only shrink. Use a max-heap via...


Submit Your Answer
Markdown supported