Register and Transfer Brazilian Receivables
Updated
Problem statement
Brazilian card transactions are registered as daily receivables. You are given two CSV strings.
transactionsCsvhas headercustomer_id,merchant_id,payout_date,card_type,amount.contractsCsvhas headercontract_id,merchant_id,payout_date,card_type,amount. It may contain only the header.
First aggregate all transactions by (merchant_id, card_type, payout_date), summing their amounts. Then apply every contract. A contract replaces the matching merchant receivable: remove that merchant row and create a row identified by the contract ID with the contract's card type, payout date, and amount.
Return CSV rows beginning with id,card_type,payout_date,amount. Sort the data rows by Unicode code points in ID, then card type, then payout date. When all three strings are equal, sort by amount numerically in ascending order. Write each output amount in base-10 notation without leading zeros.
Function
registerReceivables(transactionsCsv: String, contractsCsv: String) → String[]Examples
Example 1
transactionsCsv = "customer_id,merchant_id,payout_date,card_type,amount\ncust1,merchantA,2021-12-30,Visa,150\ncust2,merchantA,2021-12-30,Visa,200\ncust3,merchantB,2021-12-31,MasterCard,300\ncust4,merchantA,2021-12-30,Visa,50"contractsCsv = "contract_id,merchant_id,payout_date,card_type,amount"return = ["id,card_type,payout_date,amount","merchantA,Visa,2021-12-30,400","merchantB,MasterCard,2021-12-31,300"]The three matching merchant-A Visa transactions aggregate to 400. No contract replaces either receivable.
Example 2
transactionsCsv = "customer_id,merchant_id,payout_date,card_type,amount\ncust1,merchantA,2022-01-05,Visa,300\ncust2,merchantA,2022-01-05,Visa,200\ncust3,merchantB,2022-01-06,MasterCard,1000"contractsCsv = "contract_id,merchant_id,payout_date,card_type,amount\ncontract1,merchantA,2022-01-05,Visa,500"return = ["id,card_type,payout_date,amount","contract1,Visa,2022-01-05,500","merchantB,MasterCard,2022-01-06,1000"]The contract replaces merchant A's matching receivable. Merchant B's receivable remains.
Example 3
transactionsCsv = "customer_id,merchant_id,payout_date,card_type,amount\ncust1,merchantA,2022-01-07,Visa,500\ncust2,merchantA,2022-01-07,Visa,250\ncust3,merchantB,2022-01-08,MasterCard,1250\ncust4,merchantC,2022-01-09,Visa,1500"contractsCsv = "contract_id,merchant_id,payout_date,card_type,amount\ncontract1,merchantA,2022-01-07,Visa,750\ncontract2,merchantC,2022-01-09,Visa,1500"return = ["id,card_type,payout_date,amount","contract1,Visa,2022-01-07,750","contract2,Visa,2022-01-09,1500","merchantB,MasterCard,2022-01-08,1250"]Merchant A and merchant C each have a contract, so the contracts replace their receivables. Merchant B has no contract, so its receivable stays under its merchant name. Sorted by ID, the rows are the first contract, the second contract, and then merchant B.
Constraints
- Each CSV contains a valid fixed header and between
0and100000data rows. - Fields contain no commas, line breaks, or surrounding whitespace.
- IDs, card types, and payout dates are non-empty.
- Amounts are positive integers at most
10^9; every aggregate fits a signed64-bit integer. - Each contract maps to exactly one aggregated merchant receivable, and no two contracts map to the same receivable.
More Stripe Phone Screen questions
- Financial Account LedgerOA · PHONE SCREEN · Seen Nov 2026
- Business Account KYC Verification — Parts 1–5PHONE SCREEN · Seen Nov 2026
- Merchant Matching, Parts 1–2: Shared Fields and Weighted ThresholdsPHONE SCREEN · Seen Nov 2026
- Parse Boolean Rule ExpressionsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Merchant Payout Scheduler, Part 2: Per-Merchant SchedulesPHONE SCREEN · Seen Nov 2026
- Transaction Fee Calculator — Parts 1–2: Basic Fee Calculation and Conditional Fee RulesPHONE SCREEN · Seen Nov 2026
- Render a Task Tree from CSV RowsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Invoice / Payment ReconciliationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Linked Merchants Within Two HopsPHONE SCREEN · Seen Nov 2026
- Portfolio Valuation, Part 1PHONE SCREEN · Seen Nov 2026
Similar questions at other companies
- Insert an Employee into an Organization HierarchyWaymo · PHONE SCREENWaymo interview questions
- Common Words Across FilesMeta · PHONE SCREENMeta interview questions
- Summarize Server Healthcheck LogsNVIDIA · PHONE SCREENNVIDIA interview questions
- Transform Dotted Keys into a Nested MapProofpoint · ONSITE INTERVIEW
- Serialize and Deserialize a String Key-Value StoreByteDance · ONSITE INTERVIEWByteDance interview questions
- Deep Merge with a Conflict ResolverAutodesk · ONSITE INTERVIEWAutodesk interview questions
- Number of AtomsAmazon · ONSITE INTERVIEW
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- Top K Movies by Play Count from CSV DataTubi · PHONE SCREEN
- Group AnagramsWorkday · PHONE SCREEN