Stripe software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.
usage_report specifying the target region and...Input: ArrayOPEN: {"type":"OPEN","invoice_id":str,"merchant_id":str,"currency":str,"amount":int,"due_day":int}. Create an active invoice. Invoice IDs are globally unique and are never reused.UPDATE: {"type":"UPDATE","invoice_id":str,"amount":int,"due_day":int}. Replace both the amount and due day of an active invoice. Its merchant and currency do not change. Ignore the event if the invoice is unknown or inactive.CANCEL: {"type":"CANCEL","invoice_id":str}. Deactivate the specified invoice. Ignore the event if the invoice is unknown or inactive.PAY: {"type":"PAY","merchant_id":str,"currency":str,"amount":int,"invoice_id":str|null}. Match this payment using the rules below.PAY event:1. An invoice is eligible only if it is active and its merchant, currency, and amount all exactly equal those of the payment.null. An unmatched payment is not retained for future matching.Return one result for each PAY event, in event order. Amounts are integer minor currency units; there are no partial payments or currency conversions. Avoid scanning all active invoices for every payment: your implementation must run in O(n log n) total time or better for n events.Function or class signaturereconcile(events: list[dict[str, Any]]) -> list[str | None]{"events":[{"type":"OPEN","invoice_id":"inv_b","merchant_id":"m1","currency":"USD","amount":5000,"due_day":10},{"type":"OPEN","invoice_id":"inv_a","merchant_id":"m1","currency":"USD","amount":5000,"due_day":10},{"type":"OPEN","invoice_id":"inv_c","merchant_id":"m1","currency":"USD","amount":5000,"due_day":30},{"type":"PAY","merchant_id":"m1","currency":"USD","amount":5000,"invoice_id":"inv_c"},{"type":"PAY","merchant_id":"m1","currency":"USD","amount":5000,"invoice_id":"missing"},{"type":"PAY","merchant_id":"m1","currency":"USD","amount":5000,"invoice_id":null}]}Output:["inv_c","inv_a","inv_b"]Explanation: The first payment explicitly identifies an eligible invoice, so
inv_c wins despite its later due day. The second payment falls back to amount matching; inv_a and inv_b have the same due day, so inv_a wins lexicographically. The final payment matches the remaining invoice.Example 2:Input:{"events":[{"type":"OPEN","invoice_id":"inv_x","merchant_id":"m1","currency":"USD","amount":700,"due_day":1},{"type":"OPEN","invoice_id":"inv_y","merchant_id":"m1","currency":"USD","amount":700,"due_day":4},{"type":"UPDATE","invoice_id":"inv_x","amount":900,"due_day":8},{"type":"PAY","merchant_id":"m1","currency":"USD","amount":700,"invoice_id":"inv_x"},{"type":"CANCEL","invoice_id":"inv_x"},{"type":"PAY","merchant_id":"m1","currency":"USD","amount":900,"invoice_id":null}]}Output:["inv_y",null]Explanation: After the update,
inv_x is not eligible for the 700-unit payment, even though its ID was supplied. The fallback selects inv_y. Canceling inv_x leaves no eligible invoice for the 900-unit payment. Any index entries left behind by the update or cancellation must not be treated as active invoices.Constraints:0 <= n <= 200000 events; all events follow the schemas above.1 <= amount <= 10^12; 0 <= due_day <= 10^9.OPEN uses a previously unused invoice ID. Other events may reference unknown or inactive invoice IDs.time is an integer number of seconds encoded as a string. Times are nondecreasing.CHARGE contains id, time, merchant, category, and fraud, where fraud is exactly "true" or "false". Its id also identifies the charge.DISPUTE contains id, time, and charge. For this exercise, it means an analyst has overturned the referenced charge's fraud classification: change fraudulent to nonfraudulent without removing the charge from the total. A repeated dispute, a dispute of a nonfraudulent charge, or a dispute of an unknown charge has no effect.merchant_count matches when fraudulent charges are at least 3; merchant_ratio matches when total charges are at least 4 and 2 × fraudulent >= total.monitor_merchants(records: list[dict[str, str]]). The return type is up to the candidate; examples use a list of snapshots with event and merchants fields.[
{"type":"CHARGE","id":"c1","time":"0","merchant":"m1","category":"digital","fraud":"true"},
{"type":"CHARGE","id":"c2","time":"1","merchant":"m1","category":"digital","fraud":"true"},
{"type":"CHARGE","id":"c3","time":"2","merchant":"m1","category":"digital","fraud":"false"},
{"type":"CHARGE","id":"c4","time":"3","merchant":"m1","category":"digital","fraud":"true"},
{"type":"DISPUTE","id":"d1","time":"4","charge":"c1"},
{"type":"DISPUTE","id":"d2","time":"5","charge":"c2"}
][
{"event":"c1","merchants":[]},
{"event":"c2","merchants":[]},
{"event":"c3","merchants":[]},
{"event":"c4","merchants":["m1"]},
{"event":"d1","merchants":["m1"]},
{"event":"d2","merchants":[]}
]c4 both rules match. At d1 only merchant_ratio matches because 2 × 2 = 4. At d2 neither matches.Part 2 — Configurable scopes and rolling windowsmonitor_risk(records: list[dict[str, str]], extra_rules: list[dict[str, str]]). Both inputs are lists of maps with string keys and string values.id, scope (merchant or category), window (lifetime or a positive integer number of seconds), kind (count or ratio), and positive integer min_total.count rule also has a positive integer threshold. It matches when total >= min_total and fraudulent >= threshold.ratio rule instead has positive integers numerator and denominator, with numerator <= denominator. It matches when total >= min_total and denominator × fraudulent >= numerator × total. Use exact integer arithmetic.t, a window of width W includes charges with timestamps in (t-W, t]. Expire charges before applying the event. Every event advances time, including no-op disputes. Lifetime rules never expire charges.(scope, entity, rule) triple. Sort triples lexicographically by scope, then entity, then rule. Report all matching rules rather than choosing one winner. Examples use event and alerts fields.{
"extra_rules": [
{"id":"category_count","scope":"category","window":"10","kind":"count","min_total":"1","threshold":"2"},
{"id":"category_ratio","scope":"category","window":"10","kind":"ratio","min_total":"3","numerator":"2","denominator":"3"}
],
"records": [
{"type":"CHARGE","id":"c1","time":"0","merchant":"m1","category":"digital","fraud":"true"},
{"type":"CHARGE","id":"c2","time":"4","merchant":"m2","category":"digital","fraud":"true"},
{"type":"CHARGE","id":"c3","time":"6","merchant":"m2","category":"digital","fraud":"false"},
{"type":"DISPUTE","id":"d1","time":"10","charge":"c1"},
{"type":"CHARGE","id":"c4","time":"14","merchant":"m1","category":"digital","fraud":"true"}
]
}[
{"event":"c1","alerts":[]},
{"event":"c2","alerts":[{"scope":"category","entity":"digital","rule":"category_count"}]},
{"event":"c3","alerts":[{"scope":"category","entity":"digital","rule":"category_count"},{"scope":"category","entity":"digital","rule":"category_ratio"}]},
{"event":"d1","alerts":[]},
{"event":"c4","alerts":[]}
]3 × 2 = 2 × 3. At time 10, c1 expires because the lower boundary is exclusive; the category has 1/2, and its dispute changes only lifetime counts. At time 14, c2 expires and c4 enters, leaving 1/2 again. No merchant reaches either lifetime threshold.Example 3:{
"extra_rules": [
{"id":"category_count","scope":"category","window":"10","kind":"count","min_total":"1","threshold":"2"},
{"id":"category_ratio","scope":"category","window":"10","kind":"ratio","min_total":"3","numerator":"2","denominator":"3"}
],
"records": [
{"type":"CHARGE","id":"c1","time":"0","merchant":"m1","category":"digital","fraud":"true"},
{"type":"CHARGE","id":"c2","time":"1","merchant":"m1","category":"digital","fraud":"true"},
{"type":"CHARGE","id":"c3","time":"2","merchant":"m1","category":"digital","fraud":"true"},
{"type":"DISPUTE","id":"d1","time":"3","charge":"c1"},
{"type":"DISPUTE","id":"d2","time":"4","charge":"c1"}
]
}[
{"event":"c1","alerts":[]},
{"event":"c2","alerts":[{"scope":"category","entity":"digital","rule":"category_count"}]},
{"event":"c3","alerts":[{"scope":"category","entity":"digital","rule":"category_count"},{"scope":"category","entity":"digital","rule":"category_ratio"},{"scope":"merchant","entity":"m1","rule":"merchant_count"}]},
{"event":"d1","alerts":[{"scope":"category","entity":"digital","rule":"category_count"},{"scope":"category","entity":"digital","rule":"category_ratio"}]},
{"event":"d2","alerts":[{"scope":"category","entity":"digital","rule":"category_count"},{"scope":"category","entity":"digital","rule":"category_ratio"}]}
]c3 makes the category 3/3 and the merchant 3/3, matching three rules simultaneously. The merchant ratio rule still fails its minimum of 4 total charges. After d1, counts are 2/3: the merchant count rule clears, while both category rules remain, with the category ratio exactly equal to 2/3. The repeated dispute d2 must not decrement anything again.Notes:def find_shortest_transaction_path(transactions: List[Tuple[str, str]], start: str, end: str) -> List[str]:transactions = [("A", "B"), ("B", "C"), ("A", "C")], start = "A", end = "C" ['A', 'C'] transactions = [("A", "B"), ("B", "C"), ("C", "A")], start = "A", end = "D" [] processed or unprocessed). Create a function that returns all payment IDs that are unprocessed.def find_unprocessed_payments(payment_list: List[Tuple[str, str]]) -> List[str]:payment_list = [('abc123', 'processed'), ('xyz789', 'unprocessed'), ('qwe456', 'processed')] ['xyz789'] xyz789 is unprocessed.Example 2: payment_list = [('p1', 'unprocessed'), ('p2', 'unprocessed'), ('p3', 'processed')] ['p1', 'p2'] p1 and p2 are classified as unprocessed.Constraints:payment_list can be between 1 and 10^5.100 characters.processed or unprocessed. int transactionId, double amount, string date, and nested transactions. Implement methods to add a transaction and to retrieve the transaction with the highest amount.addTransaction(transactionId: int, amount: double, date: string): void: Add a transaction to the history.getMaxTransaction(): (int, double, string): Returns the ID, amount, and date of the transaction with the highest amount.addTransaction(1, 100.50, '2023-03-01')NoneExample 2:addTransaction(2, 200.75, '2023-03-02')NoneInput: getMaxTransaction()(2, 200.75, '2023-03-02')1 <= transactionId <= 10^60 <= amount <= 10^6date follows the format 'YYYY-MM-DD'.string apiKey. Ensure that the rate limiter has a method to track requests and should return a boolean indicating whether the request is allowed.trackRequest(apiKey: string): boolean: Returns true if the request is allowed, false otherwise.trackRequest('key1')truetrackRequest('key1') (100 times)true (first 100 calls)false (101st call)1 <= apiKey.length <= 10010^6 requests.PaymentProcessor class will manage different types of payments, ensuring they can be processed securely and reliably.Requirements: initiate_payment(payment_method: str, amount: float) -> str approve_transaction(transaction_id: str) -> bool decline_transaction(transaction_id: str) -> bool get_transaction(transaction_id: str) -> dict initiate_payment('credit_card', 100.00) → Output: transaction_id: 'txn_12345' approve_transaction('txn_12345') → Output: True def add_server(self, server: str) -> None: def remove_server(self, server: str) -> None: def get_next_server(self) -> str: def health_check(self) -> List[str]: def log_request(self, server: str) -> None: load_balancer = LoadBalancer()
load_balancer.add_server("server1")
load_balancer.add_server("server2")
load_balancer.get_next_server() "server1" server1 on the first call. load_balancer.add_server("server3")
load_balancer.get_next_server()
load_balancer.get_next_server() "server2" server1, the next in line is server2 followed by server3. process_transaction(transaction_id: str, amount: float) - Processes a transaction and updates internal state. get_transaction_status(transaction_id: str) - Retrieves the status of a specific transaction. refund_transaction(transaction_id: str) - Issues a refund for a completed transaction and updates the status. process_transaction(transaction_id: str, amount: float) -> None - Processes the transaction identified by transaction_id with the specified amount. get_transaction_status(transaction_id: str) -> str - Returns the status of the specified transaction.refund_transaction(transaction_id: str) -> bool - Refunds the transaction and returns True if successful, False otherwise.tp = TransactionProcessor() tp.process_transaction('txn_001', 100.0) tp.get_transaction_status('txn_001') → Output: 'successful' tp = TransactionProcessor() tp.process_transaction('txn_002', 50.0) tp.refund_transaction('txn_002') tp.get_transaction_status('txn_002') → Output: 'refunded' def create_campaign(id: str, name: str, budget: float, start_date: str, end_date: str) -> None: Creates a new campaign. def update_campaign_status(id: str, status: str) -> None: Updates the status of the campaign. def fetch_campaigns(start_date: str, end_date: str) -> List[Dict]: Returns all campaigns within the date range. def calculate_returns(id: str) -> float: Calculates returns for the specific campaign based on its spend and performance metrics. def list_campaigns_by_status(status: str) -> List[Dict]: Lists all campaigns with a specified status. def pause_campaign(id: str) -> None: Pauses an active campaign. def resume_campaign(id: str) -> None: Resumes a paused campaign. create_campaign('001', 'Holiday Sales', 10000.0, '2023-11-01', '2023-11-30') Campaign created. pause_campaign('001') Campaign paused. POST /charges: Creates a new charge.GET /charges/{chargeId}: Retrieves the status of a specific charge.GET /charges: Lists all transactions based on pagination parameters.POST /charges with body {amount: 1000, currency: 'usd', source: 'tok_visa'}201 Created with body {id: 'ch_1FZh2I2eZvKYlo2C4H2gGm7', status: 'succeeded'}Example 2:GET /charges/ch_1FZh2I2eZvKYlo2C4H2gGm7200 OK with body {id: 'ch_1FZh2I2eZvKYlo2C4H2gGm7', status: 'succeeded'}chargeId, an amount in cents, and a currency string, e.g., 'usd'.get(key: int): int: Retrieves the value of the key if the key exists in the cache, otherwise returns -1.put(key: int, value: int): void: Updates the value of the key if the key exists, and if the cache reaches its capacity, it should invalidate the least recently used item before inserting a new item.put(1, 1)NoneInput: put(2, 2)NoneInput: get(1)1Input: put(3, 3)NoneInput: get(2)-1Sign up for free to access walkthroughs, AI-generated questions, and more.
Get Started Free