Part 1 — Authorization Requests
Stripe accepts payments on behalf of merchants. These payments begin as Authorization Requests, which represent an intent to transfer funds from an end user’s credit card to a merchant. Our system receives these requests and decides the Outcome of each Authorization Request. For now, the system’s policy is to APPROVE all requests.
Authorization Requests arrive in the following format:
timestamp_seconds,unique_id,amount,card_number,merchant
Input example
5,R1,5.60,4242424242424242,bobs_burgers
10,R2,500.00,4242111111111111,a_corp
No data fields in this file will include commas, and there will be no whitespace surrounding the field values. Field values are limited to alphanumeric characters, underscores, and periods. You can assume the input has already been checked for correctness. Each timestamp is in seconds and is an integer greater than zero. Each amount is a greater-than-zero decimal value.
We have been asked by various colleagues for a human-readable report of these requests. The report should include the timestamp, unique ID, amount, and outcome — in that order, separated by spaces.
Expected output for the above input
5 R1 5.60 APPROVE
10 R2 500.00 APPROVE
Task
Write a function that produces a report for all requests, ordered chronologically, in the described format. In addition to this function, you should use tests to demonstrate that it is correct.
An example would be:
input = [
"5,R1,5.60,4242424242424242,bobs_burgers",
"10,R2,500.00,4242111111111111,a_corp"
]
output = [
"5 R1 5.60 APPROVE",
"10 R2 500.00 APPROVE"
]
Part 2 — Fraud Rules Stream
Certain colleagues upstairs have let us know that our policy of approving every Authorization Request is frowned upon by our investors. Luckily, they informed us of a separate system that our data science department built which can detect Authorization Requests that are fraudulent. With fraud, the data scientists say, nothing is set in stone. The criteria for fraud change constantly, so their system develops new Fraud Rules all the time. They’ve given us access to their system’s stream of Fraud Rules, in the following format:
time,field,value
Example
1,merchant,bobs_burgers
20,card_number,4242111111111111
Interpretation:
- The first Fraud Rule indicates: “from 1 second onward, any Authorization Request with merchant
bobs_burgersis fraudulent.” - The second indicates: “from 20 seconds onward, any Authorization Request with card_number
4242111111111111is fraudulent.”
Once a Fraud Rule is introduced, it is applicable in perpetuity (from its introduction time forward).
A new Fraud Rule cannot be applied retroactively to a previous request (i.e., rules are effective at or after their time).
Updated Task
Given a list of transactions (Authorization Requests) and a list of Fraud Rules, produce the same human-readable report as in Part 1, but now with REJECT for any request that matches an active Fraud Rule at the time of that request; otherwise APPROVE. The output must still be chronologically ordered by timestamp.
Example
transactions = [
"5,R1,5.60,4242424242424242,bobs_burgers",
"10,R2,500.00,4242111111111111,a_corp"
]
fraud_rules = [
"1,merchant,bobs_burgers",
"20,card_number,4242111111111111"
]
output = [
"5 R1 5.60 REJECT",
"10 R2 500.00 APPROVE"
]
总结
这道题本质上是一个 数据流状态问题(Stateful Stream Processing)。
面试官关注的是:
- 你的数据结构选择;
- 对时间顺序与规则生效逻辑的理解;
- 是否能在压力下清晰解释你的设计思路。
在 Stripe 的实际面试中,这类题型是用来评估候选人是否能:
- 把复杂业务转化为算法模型;
- 快速搭建合理的数据结构;
- 逻辑清晰、沟通有条理。
如果你希望进一步训练这类「系统逻辑 + 数据结构」的题目,
我们提供 Stripe / Meta / Amazon Coding Mock Interview 面试辅助服务 ,
包含完整题目讲解、代码推理与模拟答题流程。
帮助你在正式面试中精准表达、稳拿高分。