Your question is DSA Program Run Prediction. Take a moment with it on the right.
Talk me through your thinking if you like. When you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes).
Joveo's pacing service allocates a shared daily ad-spend budget across a group of job-ad campaigns based on each campaign's weight. Campaign managers can pause a campaign by setting its weight to 0, and the click-tracking service sometimes omits the spent_today field entirely for a campaign that has not received a single click yet today.
Here is the allocator and one call to it, made right after every campaign in the forklift-operator group was paused for the day:
def allocate_daily_spend(campaigns, total_budget):
allocations = {}
weights_sum = sum(c["weight"] for c in campaigns)
for c in campaigns:
share = c["weight"] / weights_sum
spend = round(total_budget * share, 2)
remaining = c["daily_cap"] - c["spent_today"]
allocations[c["name"]] = min(spend, remaining)
return allocations
paused_group = [
{"name": "forklift-operator-day", "weight": 0, "daily_cap": 500},
{"name": "forklift-operator-night", "weight": 0, "daily_cap": 800},
]
print(allocate_daily_spend(paused_group, 1000))
State exactly what happens when this call runs: does it complete, and if not, which line raises an exception and of what type? Then, separately, point out the other bugs in allocate_daily_spend that this particular call does not happen to trigger but that would still break the pacing service in production, and explain what input would trigger each one.