Card authorization report with fraud rules
I was asked this
No reports yet. Sign in to say where you were asked it.
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.
Reconstructed from the reported question; details may differ from what interviewers ask.
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. Free with an account: one full answer per company.
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. Free with an account: one full answer per company.
Sign in to submit your code; every attempt is kept here.
