Code RoomBacklog after k drains
MediumPrep Room Coding #472

Backlog after k drains

CodingAlgorithms & data structuresEntry–Mid~15 min

Each worker queue on a busy server has a backlog measured in pending jobs. You are allowed to run a drain routine exactly k times. Each run picks one queue and removes floor(b / 2) jobs from it, where b is that queue's current backlog. To shrink the total backlog fastest, every run should target the queue with the largest current backlog. Return the total backlog remaining after the k runs. Example: queues = [5, 4, 9], k = 2 gives 12 — drain 9 to 5, then drain a 5 to 3, leaving 3 + 4 + 5.

Implement
remaining_backlog(queues: list[int], k: int) → int
Examples
in[[5,4,9],2]out12
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 15 min
InputExpectedGot
[[5,4,9],2]12not run yetsample