Invoice reminder emails and delinquent customers
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Stripe's onsite coding (debug, integrate, build) round, last asked Oct 2024. It tests sorting, simulation and scheduling.
Each customer has one invoice with a time and an amount. A configurable schedule says which emails to send, at offsets relative to the invoice time; the largest offset is the due date. Payments arrive in no particular order. Produce the email log in time order, sending only the emails that are still needed, and then list the customers who still owed money on their due date.
Interface
Unless you agree on a different interface with the interviewer, assume:
-
invoice_emails(schedule: list[str], invoices: list[str], payments: list[str]) -> list[str]- Schedule rows are
offset,title; invoice rowsinvoice_time,name,amount; payment rowspayment_time,name,amount. - Each email is due at
invoice_time + offset. Before it, apply every payment made at or before that time. Send it only if the customer still owes a positive amount, astime: [title] Invoice for name for amount dollars, showing the amount still owed. - Order emails by time, then invoice input order, then schedule order.
- Then append
Delinquent customers:andname owes amount dollarsfor each customer with a positive balance at the due time, in invoice order.
- Schedule rows are
Example
schedule = ["-10,Upcoming", "0,New", "20,Reminder", "30,Due"]
invoices = ["0,Alice,200", "1,Bob,100"]
payments = ["-9,Alice,100", "1,Alice,50", "0,Bob,100"]
-> ["-10: [Upcoming] Invoice for Alice for 200 dollars",
"-9: [Upcoming] Invoice for Bob for 100 dollars",
"0: [New] Invoice for Alice for 100 dollars",
"20: [Reminder] Invoice for Alice for 50 dollars",
"30: [Due] Invoice for Alice for 50 dollars",
"Delinquent customers:",
"Alice owes 50 dollars"]
# Bob paid in full at time 0, so his later emails are skipped
schedule = ["-5,Upcoming", "0,Due"], invoices = ["10,Cara,50"], payments = ["5,Cara,50"]
-> ["Delinquent customers:"] # the payment at time 5 lands before the email at time 5
Constraints
- Up to 20 schedule rows with unique, increasing offsets; up to 1,000 invoices with unique names; up to 10,000 payments.
- Amounts are positive integers up to 10^9. Payments after the due time do not affect delinquency.
Clarifying questions
- Is a payment at the same time as an email applied before the email? (Yes.)
- Can a customer overpay, and does the extra carry anywhere?
- Can a customer have more than one invoice?
- Should emails for customers with a zero balance be skipped or logged as skipped?
What a strong answer covers
- Generating every (time, invoice, schedule) event, sorting it with the stated tie rules, and sorting payments by time.
- A merge of the two sorted streams: before each email, apply every payment up to its time.
- Recording each customer's balance at their due-date event for the delinquency list.
- O((E + P) log(E + P)) time for E emails and P payments.
- Tests: payment at the exact email time, overpayment, equal times across customers.
Follow-ups
- Customers can have several invoices; payments apply to the oldest first.
- Run this as a daily job instead of over the whole history. What state do you keep?
- Add late fees after the due date.
Where it's asked
- Stripe · Onsite coding: debug, integrate, build · Last asked Oct 202460 min · Project editor with starter code and tests: fix bugs in an unfamiliar codebase, wire an external API spec into a service, or complete a skeleton in parts · Varies by session: some onsites have one AI-assisted session and an integration session without AI
What it tests
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
