This question evaluates the ability to aggregate transactional loan records and match repayment transactions to outstanding loans, testing competencies in data aggregation, ordered matching, stateful handling of partial and split payments, and analysis of time and space complexity.
You are building a loan servicing tool.
You are given two datasets.
Each raw loan record has the following fields:
loan_id
: string
customer_id
: string
amount
: positive integer
created_at
: timestamp
Multiple records may belong to the same loan_id. Write a function that aggregates all records with the same loan_id into a single loan summary containing:
loan_id
customer_id
created_at
of the earliest record for that loan
total_amount
: the sum of all amounts for that loan
You may assume all records for the same loan_id belong to the same customer_id.
You are then given the aggregated loans from Part 1 and a list of repayment transactions. Each transaction has:
txn_id
: string
customer_id
: string
amount
: positive integer
timestamp
: timestamp
Match transactions to outstanding loans using these rules:
customer_id
.
created_at
.
Return:
(txn_id, loan_id, matched_amount)
Discuss the time and space complexity of your approach.