Last Updated: 29 Sep, 2025

Stock Ledger Reconciliation

Hard
Asked in company
Addepar

Problem statement

You are an auditor for a financial firm, tasked with reconciling stock inventories from three different ledgers: a starting ledger, a transactions ledger, and a final ledger. Each ledger is represented as a list of strings.


start list: Contains the initial count of each stock at the beginning of the day. Format: "{stock_name}:{count}".


transactions list: Contains all the buy (+) or sell (-) transactions that occurred during the day. Format: "{stock_name}:{change}". A positive change is a buy, a negative change is a sell.


final list: Contains the expected final count of each stock at the end of the day. Format: "{stock_name}:{count}".


Your task is to calculate the actual final stock counts by applying the transactions to the starting counts and then compare this result with the final ledger. You must generate a "reconciliation report" that lists all stocks with discrepancies.


Input Format:
The first line of input contains an integer N1, the number of records in the start list.

The next N1 lines contain the records for the start list.

The next line contains an integer N2, for the transactions list.

The next N2 lines contain the records for the transactions list.

The next line contains an integer N3, for the final list.

The next N3 lines contain the records for the final list.


Output Format:
For each stock that has a discrepancy between your calculated final count and the final ledger's count, print a line in the format: "{stock_name}:{difference}".

The difference is calculated as (calculated_final_count - final_ledger_count). A positive difference means the calculated amount was higher; a negative difference means it was lower.

If a stock exists in one final calculation but not the other, it is also a discrepancy.

The output lines must be sorted alphabetically by stock name.

If there are no discrepancies, print No discrepancies found.


Note:
A stock might appear multiple times in any list (e.g., multiple transactions for the same stock). These should be aggregated.

A hash map (or dictionary) is the ideal data structure to store the aggregated counts for each stock.