Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Join Transactions and Flag Anomalies
00:00
5 left

Join Transactions and Flag Anomalies

MediumPython

Problem

Given two datasets of transactions and refunds, write a function to join them and flag any anomalies.

Implement reconcile_transactions(transactions, refunds). Each transaction has a unique string transaction_id, integer amount in cents, and currency. Each refund has a string refund_id, transaction_id, integer amount, and currency. Return one anomaly object per affected transaction, ordered by transaction_id. Flag unmatched refunds, currency mismatches, and cases where total refunds exceed the transaction amount.

Input: two lists of dictionaries. Output: a list of dictionaries containing transaction_id, types, transaction, and refunds.

Constraints

  • 0 <= len(transactions), len(refunds) <= 10^4
  • Each transaction_id and refund_id is a non-empty string
  • Transaction IDs are unique in transactions
  • Amounts are non-negative integers representing cents
  • Each refund references at most one transaction ID
  • Return anomalies ordered lexicographically by transaction_id

Function Signature

def reconcile_transactions(transactions, refunds):
Interviewer

Your question is Join Transactions and Flag Anomalies. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.