FastPrepMonthly Latest-Balance Reconciliation

Monthly Latest-Balance Reconciliation

Stripe logoStripeMediumFULLTIMEPHONE SCREEN
Learn

Problem statement

Each CSV row has canonical fields bank,account,endDate,balance, where endDate is ISO YYYY-MM-DD and balance is a signed integer. Given a target month in YYYY-MM form, find the latest row in that month for every bank/account present in primaryRows.

Compare its balance with the latest same-month row for the same bank/account in comparisonRows. Emit bank,account,endDate,balance,MATCH when balances agree, otherwise end with NOT_MATCH. Return rows sorted by bank, then account.

Function

reconcileMonthlyBalances(primaryRows: String[], comparisonRows: String[], month: String) → String[]

Examples

Example 1

primaryRows = ["HSBC,123,2021-12-31,150","BA,566,2021-12-31,300"]comparisonRows = ["HSBC,123,2021-12-30,150","BA,566,2021-12-31,250"]month = "2021-12"return = ["BA,566,2021-12-31,300,NOT_MATCH","HSBC,123,2021-12-31,150,MATCH"]

HSBC balances agree; BA balances differ. Output is sorted.

Example 2

primaryRows = ["A,1,2022-01-01,10","A,1,2022-01-31,20"]comparisonRows = ["A,1,2022-01-15,20"]month = "2022-01"return = ["A,1,2022-01-31,20,MATCH"]

Only each table's latest row in January participates.

Example 3

primaryRows = ["A,1,2020-05-31,-5"]comparisonRows = []month = "2020-05"return = ["A,1,2020-05-31,-5,NOT_MATCH"]

A missing comparison account does not match.

Constraints

  • Each input contains at most 10^5 rows.
  • Fields contain no commas; dates and month are valid canonical ISO strings.
  • At most one row exists per bank/account/endDate within one input.

More Stripe problems

See Stripe hiring insights
public String[] reconcileMonthlyBalances(String[] primaryRows, String[] comparisonRows, String month) {
    // Write your solution here.
}
primaryRows["HSBC,123,2021-12-31,150","BA,566,2021-12-31,300"]
comparisonRows["HSBC,123,2021-12-30,150","BA,566,2021-12-31,250"]
month"2021-12"
expected["BA,566,2021-12-31,300,NOT_MATCH", "HSBC,123,2021-12-31,150,MATCH"]
Checking account…