Skip to content
RED SAGSkills

Reconcile Bank and Ledger

At month end, finance compares the bank statement bank with the company ledger books. Each entry is { ref, amountCents }. References are typed by people, so compare them after trimming surrounding spaces and converting to upper case; within one list, normalised refs are unique.

Return an object with four arrays of normalised refs, each sorted ascending (plain string order):

- matched: in both lists with the same amount - amountMismatch: in both lists with different amounts - missingInBooks: only on the bank statement - missingInBank: only in the ledger

Example 1

Input: bank = [{"ref":"INV-1","amountCents":1000},{"ref":" inv-2 ","amountCents":500},{"ref":"INV-3","amountCents":700}], books = [{"ref":"inv-1","amountCents":1000},{"ref":"INV-2","amountCents":550},{"ref":"INV-4","amountCents":300}]
Output: {"matched":["INV-1"],"amountMismatch":["INV-2"],"missingInBooks":["INV-3"],"missingInBank":["INV-4"]}
Explanation: " inv-2 " and "INV-2" are the same ref with different amounts.

Example 2

Input: bank = [], books = []
Output: {"matched":[],"amountMismatch":[],"missingInBooks":[],"missingInBank":[]}

Constraints

  • 0 <= bank.length, books.length <= 10^5
  • Amounts are integers
Hint 1

Index one list by normalised ref in a Map, then walk the other.

Hint 2

Anything left unvisited in the map belongs to the other "missing" bucket.

Good practice for: Backend Developer, Full Stack Developer, Blockchain Developer, Data Engineer, Automation Test Engineer, Database Administrator

Run checks your code on 3 sample tests. Submit runs all 6 tests, including hidden ones, and earns points. Use console.log to debug. Python's first run can take a few seconds while it starts.