← 返回 goldmansachs 的题目列表In-Memory Transaction Authorizer with MCC Blacklists and Rolling Velocity Limit
类型:online_judge
Problem: In-Memory Transaction Authorizer (MCC Blacklists + User Overrides + Rolling Velocity Limit)
Implement a transaction authorizer TransactionAuthorizer that decides whether to approve or decline a transaction request from a card network.
Assume everything is in-memory (no persistence).
Transaction fields
Each transaction has:
user_id (string)
transaction_id (string)
mcc (string, merchant category code)
timestamp (integer, in seconds)
amount (decimal, or integer cents)
Example:
{
"user_id": "1111",
"transaction_id": "0001",
"mcc": "9999",
"timestamp": 0,
"amount": 10.00
}
Part 1: Single MCC rejection rule
Implement approve(transaction) -> boolean:
Rule 1: decline (false) if mcc == "9999", otherwise approve (true).
Part 2: Global + per-user MCC rejection lists
Extend Part 1:
Globally rejected MCCs: { "9999", "0000" }
User-specific rejected MCCs:
user_id == "1234": reject { "1111", "2222" }
user_id == "5678": reject { "5555", "6666" }
Decision order:
If the transaction mcc is in the global reject set, decline.
Else if the user has a user-specific reject set and mcc is in it, decline.
Otherwise approve.
Part 3: Rolling 1-hour velocity limit
Add a spending velocity limit on top of Part 2:
Rule 3: For each user, if the sum of attempted transaction amounts within a rolling 1-hour window exceeds $5000, decline further transactions.
Notes:
Timestamp unit is seconds.
For a transaction at time t, the rolling window is the last 3600 seconds (choose (t-3600, t] or [t-3600, t] and be consistent; explain your choice).
“Attempted transactions” means both approved and declined transactions contribute to the running window total.
Example
For a single user:
| timestamp | amount | result | |---:|---:|---| | 0 | 500 | approved | | 60 | 2000 | approved | | 3660 | 3000 | approved | | 7260 | 2001 | rejected | | 7261 | 3000 | rejected |
Requirements
Implement TransactionAuthorizer (any language; Java class stub is acceptable).
Support the three rules (can be implemented incrementally or via feature toggles).
Explain your data structure choices and time/space complexity.
Example
Input
5
1111 0001 1234 0 500.00
1111 0002 1234 60 2000.00
1111 0003 1234 3660 3000.00
1111 0004 1234 7260 2001.00
1111 0005 1234 7261 3000.00
Output
approved
approved
approved
rejected
rejected