Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started

DSA Program Run Prediction

HardCoding00:00
Practice interviewer
In session
5 left
00:00

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).

You need to log in / sign up to chat or submit.

Problem

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.