← Gym/Transaction Reconciliation
00:00/ 22 min

🧭 Do not search for the first 15 minutes. When stuck: re-read the requirements → define I/O → choose the data structure → trace a small example by hand → write code.

Implement reconcile(a, b), which compares the transaction records two systems kept independently and classifies only the discrepancies, in three categories.

Input

Both arguments are lists of (transaction id, amount) tuples.

python
system_a = [("T1", 100), ("T2", 200), ("T3", 300)]
system_b = [("T2", 200), ("T3", 250), ("T4", 400)]

Rules

  • When an id appears several times within one list, sum the amounts. A single transaction arriving split across several rows is common.
  • Compare after summing — reconciliation happens once per id.
  • Amounts are integers and may be negative (refunds).

Output

Return a dictionary with three keys.

python
{
    "missing_in_b": ["T1"],                 # ids only in a
    "missing_in_a": ["T4"],                 # ids only in b
    "amount_mismatch": [("T3", 300, 250)],  # present in both, amounts differ
}
  • Each amount_mismatch tuple is ordered (id, a's amount, b's amount).
  • An id present in both with matching amounts goes into none of the lists.

Ordering

All three lists keep their order of first appearance in the source.

  • missing_in_b and amount_mismatch → order of first appearance in a
  • missing_in_a → order of first appearance in b

Do not sort — reconciliation reports are read in ledger order by convention.

Level 1 · Reconciliation

Implement reconcile(a, b). The rules and output shape match the shared spec.

  • Either list may be empty (including both).
  • When nothing is out of line, all three lists are empty.