Stage 1 of 2: Monthly charges
Background. A card's charges mix one-off spending (a ferry fare, a coffee, a single purchase) with bills that come back on a schedule. The bills are what a cardholder wants listed, one line each.
Implement monthly_charges(charges) in recurring.py. It returns a list of strings: one summary line for each monthly series in charges.
Charges
charges is a list of dicts in no particular order. Each has four keys:
"on": the day of the charge, an ISO date stringYYYY-MM-DD"payee": who was paid, a string"cents": the amount in cents, an int"currency": a three-letter code such as"EUR"
A call gets at most 2,000 charges. The standard library's datetime is available.
Series
- A series is every charge with the same
payee, the samecentsand the samecurrency. Payees are compared exactly, case and spaces included. - A charge whose
centsis 0 or less is a refund or a correction: it is ignored and belongs to no series. - A series is monthly when it has at least three charges and, sorted by date, every two neighbours are 28 to 31 days apart, both ends included. Two charges of a series on the same day are 0 days apart, so that series is not monthly.
The rule is about the whole series: when one pair of neighbours is out of step, the series is not monthly and is not reported at all.
Lines
One line per monthly series:
<payee>: <amount> <currency> every month
<amount> is cents / 100 with exactly two decimals and no separator for thousands: 1450 is 14.50, 700 is 7.00, 85 is 0.85, 123456 is 1234.56. The lines are sorted by payee (plain string order, Python's default for str), then by cents as a number, then by currency. With no monthly series the result is [].
Example
monthly_charges([
{"on": "2027-01-31", "payee": "Sorrel Broadband", "cents": 4450, "currency": "EUR"},
{"on": "2027-02-28", "payee": "Sorrel Broadband", "cents": 4450, "currency": "EUR"},
{"on": "2027-03-31", "payee": "Sorrel Broadband", "cents": 4450, "currency": "EUR"},
{"on": "2027-02-20", "payee": "Sorrel Broadband", "cents": -4450, "currency": "EUR"},
{"on": "2027-02-03", "payee": "Harbourline Ferry", "cents": 380, "currency": "EUR"},
{"on": "2027-02-06", "payee": "Harbourline Ferry", "cents": 380, "currency": "EUR"},
{"on": "2027-02-15", "payee": "Harbourline Ferry", "cents": 380, "currency": "EUR"},
{"on": "2027-03-07", "payee": "Harbourline Ferry", "cents": 380, "currency": "EUR"},
{"on": "2027-01-12", "payee": "Ashgrove Lockers", "cents": 2100, "currency": "GBP"},
{"on": "2027-02-11", "payee": "Ashgrove Lockers", "cents": 2100, "currency": "GBP"},
])
returns ["Sorrel Broadband: 44.50 EUR every month"]. Sorrel Broadband's charges are 28 and 31 days apart, and its refund belongs to no series. Harbourline Ferry's are 3, 9 and 20 days apart. Ashgrove Lockers has only two.
Done when Submit goes green.
Constraints
- Python 3.12+ standard library only
- Editable:
recurring.py - Read-only: all
tests/test_*.pyfiles - A call gets at most 2,000 charges
What comes after stage 1
The next stage opens once the tests for the one before it pass. Each raises the bar, the way an interviewer does in the room.
- Stage 2: Every period. Bills repeat on more than one rhythm, and each has to be named.
The files you get
- Yours to edit: recurring.py.
- Read-only: tests/__init__.py.
- Tests you can read and run: tests/test_part1.py. Hidden tests run on Submit.
The round: an agent in the editor
The assistant here works like the one in the interview IDE. It reads your files, runs code and proposes changes, and you accept or reject each one. It doesn't volunteer ideas, so what gets built is what you asked for. Along the way the interviewer asks about your decisions, and at the end the report says what you checked and what you accepted unread.
Frequently asked, briefly answered
Is Recurring Charges free?
It is a Pro problem. Free plan includes one complete problem, plus the first stage of several more, so you can see how a round works before you pay.
Which company asks something like this?
Ramp. It is modelled on Ramp's round: An onsite round listed as "AI Coding / AI Pair Programming" in a candidate's loop agenda; Ramp has published nothing about it, and no candidate report we can cite describes it yet. Based on candidates' reports of Ramp interviews. Nyrion wrote this version, so the question you get may differ.
Do I bring my own AI tool?
No. The assistant is in the editor, same as in the interview IDEs at Meta, Stripe and Amazon. What you choose at Begin is the format: an agent that proposes changes you accept or reject, or an answer-only assistant that can't write code.
What does the interviewer ask?
4 questions along the way about your own code, and one at the end about the whole session. A weak answer gets one follow up. The answers go into the report, which ends with a hire or no hire verdict.
Start the problem
Sign in and the problem opens where you left it. New here? An account takes a minute to create, and the Pro plan starts at the first stage of this problem.
More like it: every practice problem, how Ramp runs its AI round, the AI coding interview guide.