← 返回 stripe 的题目列表Invoice and Payment Matching (with datetime parsing/comparison)
类型:online_judge
Invoice & Payment Matching (with datetime parsing/comparison)
You are given two sets of records:
Invoices: each record has invoice_id, customer_id, amount, currency, created_at (a datetime string).
Payments: each record has payment_id, customer_id, amount, currency, paid_at (a datetime string).
Implement a matcher that maps invoices to payments.
Matching rules
Match only within the same customer_id and the same currency.
A payment can match at most one invoice (1:1).
Match only if payment.amount == invoice.amount.
Time constraint: paid_at >= created_at.
If multiple payments can match the same invoice, choose the one with the earliest paid_at; if still tied, choose the lexicographically smallest payment_id.
Output invoice_id -> null if no match exists.
Input / Output
Input: two lines of JSON.
Line 1: invoices array
Line 2: payments array
Output: a single JSON object mapping each invoice_id to a payment_id or null.
Constraints
1 <= len(invoices), len(payments) <= 2e5
amount is a non-negative integer (in the smallest currency unit, e.g. cents)
created_at and paid_at share the same datetime-string format and must be compared correctly
Example
Input
[{"invoice_id":"i1","customer_id":"c1","amount":100,"currency":"USD","created_at":"2020-01-01T00:00:00Z"},{"invoice_id":"i2","customer_id":"c1","amount":100,"currency":"USD","created_at":"2020-01-02T00:00:00Z"}]
[{"payment_id":"p1","customer_id":"c1","amount":100,"currency":"USD","paid_at":"2020-01-01T01:00:00Z"},{"payment_id":"p2","customer_id":"c1","amount":100,"currency":"USD","paid_at":"2020-01-03T00:00:00Z"}]
Output
{"i1":"p1","i2":"p2"}