Align Bank Statement Lines With Ledger Entries at Minimum Cost

Last updated: November 29, 2026

Quick Overview

A bank statement and the internal ledger each list amounts in time order, but amounts can differ slightly and either side can have extra lines. Find an order-preserving alignment that pairs lines whose amounts are within a tolerance, minimizing total amount difference plus a fixed penalty per unmatched line, and return the matched pairs.

Stripe
Coding & Algorithms
Software Engineer
Stripe
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


A bank statement and the internal ledger each list amounts in time order, but amounts can differ slightly and either side can have extra lines. Find an order-preserving alignment that pairs lines whose amounts are within a tolerance, minimizing total amount difference plus a fixed penalty per unmatched line, and return the matched pairs.

Reconciling Stripe's internal ledger with what partner banks report is a core finance infrastructure problem, and mismatches from fees, FX rounding or missing lines are routine. This maps to an edit-distance style 2D DP, and the interviewer checks the recurrence, the tolerance constraint and reconstruction of the actual alignment.

What the Interviewer Expects
  • Recognize the problem as sequence alignment and define `dp[i][j]` precisely
  • Allow a match only when the amount difference is within tolerance
  • Charge a skip penalty for unmatched lines on either side
  • Reconstruct matched pairs by walking back through the table
  • Discuss the $O(nm)$ cost and how to band it for long statements
Key Topics to Cover
dynamic programming
edit distance
sequence alignment
reconciliation
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you choose the skip penalty relative to the tolerance?
  • How would you scale this to statements with a million lines per day?
  • What if lines can be reordered within the same day?
  • How would you handle one bank line that corresponds to two ledger entries?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Inputs: stmt and ledger as lists of integer cents, a tolerance tol and skip penalty P. Matching stmt[i] to ledger[j] costs abs(stmt[i] - ledger[j]) and is only allowed if that is at most...

High-Level Design

dp[i][j] is the minimum cost to align the first i statement lines with the first j ledger lines. Base cases: dp[i][0] = i * P and dp[0][j] = j * P. Transition: skip a statement line (`dp[i-1...


Submit Your Answer
Markdown supported