coding
Stripe
PayPal
Square

Stripe Coding Interview: Match Payments to Invoices

Topics:
String Processing
Hash Table
Sorting
Roles:
Software Engineer
Backend Engineer
Payments Engineer
Experience:
Entry Level
Mid Level
Senior

Question Description

Overview

You are given two collections — invoices and payments — and must implement a deterministic, one-to-one matching procedure that assigns at most one invoice to each payment. For every payment (preserve input order) you should attempt prioritized strategies: identifier match (invoice_id or account_id), exact amount match, then a configurable range/forgiveness match. Once an invoice is assigned it cannot be reused.

What you'll be asked to do

You should return, for each payment, the payment_id, the matched_invoice_id (or null), and the signed numeric difference payment_amount - invoice_amount (or null if unmatched). If multiple invoices satisfy a strategy, pick the invoice with the earliest due date; if due dates tie, apply a deterministic tie-breaker (e.g., lexical invoice_id). Exact equality takes precedence over range matches.

Flow or stages to implement

  1. Process payments in input order.
  2. For each payment, apply strategies in priority order and stop at the first that yields candidates.
  3. Filter out invoices already assigned, sort candidates by due date and tie-breaker, pick the first.
  4. Compute signed difference and mark invoice used.

Skill signals interviewers look for

You should demonstrate careful handling of dates and numeric comparisons (currency/tolerance), deterministic ordering and tie-breakers, efficient lookups (hash maps / indexing), and stable, reproducible behavior. Be ready to discuss edge cases (duplicate identifiers, floating-point tolerance, time zones, and performance at scale).

Common Follow-up Questions

  • How would you change the algorithm to allow a single payment to cover multiple invoices (partial allocations) while maintaining determinism?
  • How do you handle currency rounding and floating-point tolerance so amount comparisons remain robust across locales?
  • If the forgiveness threshold is dynamic per account, how would you design data structures and indexing to efficiently apply per-payment thresholds?
  • How would you extend the tie-breaker to prefer invoices belonging to the same payee_name (case-insensitive substring) before falling back to invoice_id?
  • Describe performance and memory optimizations for matching when invoices and payments are streams with millions of records.

Related Questions

1Design an algorithm to reconcile a list of bank transactions to ledger entries with prioritized matching rules
2Match orders to shipments: implement deterministic pairing by identifier, exact quantity, then tolerance
3Implement invoice reconciliation allowing fuzzy payee name matches and configurable thresholds

Explore More Questions

Practice This Question with AI

Get real-time hints, detailed requirements, and insightful analysis of the question.

Match Payments to Invoices - Stripe Coding Question | Voker