← 返回 stripe 的题目列表Match Invoices with Payment Notes
类型:online_judge
Given a list of payment records and a list of invoice records, find the invoice that matches each payment. Payment records contain an invoice ID, amount, and memo. If an invoice ID is found in the memo, return the corresponding invoice. For payments without an invoice ID, find the invoice with the same amount and the earliest due date. Return "cannot find matching invoice" if no match is found. The time complexity should be O(n).
Example:
Payment Records:
{"id": "p1", "amount": 100, "memo": "Paying off: i1001"}
{"id": "p2", "amount": 200, "memo": "No invoice ID"}
Invoice Records:
{"id": "i1001", "amount": 100, "dueDate": "2023-01-01"}
{"id": "i1002", "amount": 200, "dueDate": "2023-02-01"}
Output:
Payment p1 matches invoice i1001
Payment p2 matches invoice i1002
Example
Input
[{"id": "p1", "amount": 100, "memo": "Paying off: i1001"}, {"id": "p2", "amount": 200, "memo": "No invoice ID"}], [{"id": "i1001", "amount": 100, "dueDate": "2023-01-01"}, {"id": "i1002", "amount": 200, "dueDate": "2023-02-01"}]