Skip to content

39. Reconcile Two Sources (Full Outer Join)

Difficulty: Hard · Topics: Joins, Null Handling, Conditional Logic, Filtering & Selection

Finance must reconcile the internal ledger with the bank statement, both keyed by txn_id.

Return only the problems: txn_id, ledger_amount, bank_amount and status:

Transactions that match exactly are left out.

Row order does not matter; column names must match. Your code is graded on 3 test cases, including hidden edge cases.

Sample data

ledger

txn_idamount
1100
2250
375

bank

txn_idamount
1100
2245
460

Expected output

txn_idledger_amountbank_amountstatus
2250245amount_mismatch
375nullmissing_in_bank
4null60missing_in_ledger

Hints

Hint 1Rename amount on each side first so both survive the join.
Hint 2A full outer join on txn_id keeps rows from either side.
Hint 3A when chain without otherwise gives null for matches; filter those out.

PySpark functions you'll practise

Related problems

Browse

Topics: Window Functions · Joins · Aggregations · Pivot, Unpivot & Rollup · Arrays · Null Handling · Conditional Logic · Dates · Filtering & Selection · Strings

Difficulty: Easy · Medium · Hard · PySpark interview roadmap · All problems