Card authorization report with fraud rules
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Stripe's technical phone screen, last asked Jan 2026. It tests parsing, sorting and simulation.
A payment platform receives authorization requests: a card holder's intent to pay a merchant. Write a function that decides each request and returns a report.
Each request is a CSV string:
<timestamp_seconds>,<request_id>,<amount>,<card_number>,<merchant>
The input is well-formed. Fields contain no commas or spaces. Timestamps are positive integers. Amounts are positive decimals. Request ids are unique. The list is not guaranteed to be in time order.
Part 1
Approve every request. Return one line per request, sorted by timestamp (ties keep input order), in the format:
<timestamp> <request_id> <amount with 2 decimals> <APPROVE|REJECT>
Write tests that show it works.
Part 2
Add a list of rules. Each rule is "<field>,<op>,<value>", where field is amount, card or merchant, and op is one of >, >=, <, <=, ==, !=. Reject a request that matches any rule.
Part 3
Add fraud reports, each "<timestamp>,<request_id>", which say an earlier request was fraudulent. From the report's timestamp on (inclusive), reject every request made with that request's card. Earlier decisions do not change. Ignore reports for unknown ids.
Example
requests = ["30,r3,12.5,4000111122223333,cafe_one",
"10,r1,250,4000999988887777,bike_shop",
"20,r2,7.25,4000111122223333,book_nook"]
Part 1 gives ["10 r1 250.00 APPROVE", "20 r2 7.25 APPROVE", "30 r3 12.50 APPROVE"].
With the rule amount,>,100, r1 becomes REJECT.
With the fraud report 25,r2 (no rules), r3 becomes REJECT, because it uses the same card as r2 and comes after the report. r2 itself stays APPROVE.
Clarifying questions
- In Part 1, is every request approved, so the report is only about sorting and formatting?
- In Part 2, how are
amountvalues compared: as decimals? Arecardandmerchantonly compared with==and!=, or also with<as strings? - In Part 3, can a fraud report refer to a request that comes after it in time, and does it still block that card from the report's timestamp on?
- Is the report's timestamp compared with
>=, so a request at exactly that second is rejected? - Should amounts be rounded half up to 2 decimals in the output?
What a strong answer covers
- Parses requests into records with
Decimalamounts and their input position, then sorts by(timestamp, position). - Parses each rule once into a field, an operator from a small table (
operator.gtand so on) and a typed value, and rejects a request when any rule matches. Invalid rules raise a clear error. - Turns fraud reports into a map from card to the earliest report timestamp, after looking up each reported request's card, and rejects requests with that card at or after that time. Reports for unknown ids are skipped.
- O(n log n + n * rules) time, with output formatted to exactly two decimals.
- Tests written as asked: the example for each part, equal timestamps keeping input order, each operator, a fraud report at the same second as a request, an unknown id, and several reports for one card.
Follow-ups
- Add a velocity rule: reject a card's request when it has more than
crequests in the lastwseconds. - Rules combine with AND and OR.
- Requests arrive as a stream and must be decided in real time.
- Show the reason for each rejection in the report.
Where it's asked
- Stripe · Technical phone screen · Last asked Jan 202660 min · One realistic task in parts, in a project editor (CoderPad project mode or HackerRank Projects) with several files and tests
What it tests
parsing · sorting · simulation · hash map
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. New accounts get 5 credits: each one unlocks a question for good.
What the labs asked this week
A weekly email of what OpenAI, Anthropic and the other top AI labs asked engineers, round by round.
Sign in to submit your code; every attempt is kept here.
