Daily Closing Balance and First Overdraft Day for Prepaid Ad Accounts
Last updated: November 29, 2026
Quick Overview
Prepaid Meta ad accounts receive top-ups and are charged for spend. From a transactions table, compute each account's balance at the end of every day it had activity and the first day its balance went negative, if ever.
Meta
November 29, 20260
0
0 solved
Prepaid Meta ad accounts receive top-ups and are charged for spend. From a transactions table, compute each account's balance at the end of every day it had activity and the first day its balance went negative, if ever.
A running-total question asked in Meta ads billing and payments analytics screens, where prepaid accounts in many markets can briefly overdraw before delivery stops. The interviewer checks a cumulative sum ordered correctly and picking the first qualifying day.
What the Interviewer Expects
- Aggregate transactions to account and day
- Use a running SUM ordered by date
- Return the end-of-day balance
- Find the first negative day with MIN over a condition
- Keep accounts that never went negative
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would you produce a balance for every calendar day, including quiet days?
- Spend posts later than it happens: which timestamp do you use?
- How would you measure how long accounts stay negative?
- How do refunds of top-ups fit in?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
prepaid_txns(account_id, txn_ts, amount_usd, txn_type): top-ups are positive, spend charges negative, refunds whichever sign applies. Balances start at zero when the account opens. End of day uses U...
Approach
Sum amounts per account and day, then take a running SUM over days. Since the daily sum already nets all intra-day movements, the running total at each row is the closing balance. For the first overdr...