PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Affirm

Compute Balances and Minimize Settlements

Last updated: May 10, 2026

Quick Overview

This question evaluates transactional data aggregation and net-balance computation skills alongside combinatorial optimization for minimizing settlement transfers, testing competencies in data structures, numeric aggregation, and algorithmic reasoning.

  • hard
  • Affirm
  • Coding & Algorithms
  • Software Engineer

Compute Balances and Minimize Settlements

Company: Affirm

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Onsite

You are building a daily ledger service. A transaction record has three fields: `timestamp`, `user_id`, and `delta_amount`. `delta_amount` can be positive or negative and represents how that user's balance changes during the day. All amounts are integers. 1. Given a list of transaction records for a single day, compute each user's end-of-day net balance, assuming every user's starting balance is 0. 2. Using the resulting balances, generate a settlement plan with the minimum possible number of transfers so that every user's final balance becomes 0. A user with a negative balance must pay money, and a user with a positive balance must receive money. Each settlement transfer should be represented as `(from_user, to_user, amount)`. Notes: - Users whose balance is 0 do not need to appear in the settlement plan. - You may assume the sum of all balances is 0. - For the exact-minimum settlement part, assume the number of users with non-zero balance is small enough to permit an exponential-search solution if needed.

Quick Answer: This question evaluates transactional data aggregation and net-balance computation skills alongside combinatorial optimization for minimizing settlement transfers, testing competencies in data structures, numeric aggregation, and algorithmic reasoning.

Related Interview Questions

  • Determine Redeemable Promotion Offers - Affirm (medium)
  • Compute Available Offers per User - Affirm (easy)
  • Aggregate loans and match repayments - Affirm (medium)
  • Implement a timestamped map - Affirm (medium)
  • Detect fraud events and extract PII - Affirm (medium)
Affirm logo
Affirm
Feb 27, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
3
0
Loading...

You are building a daily ledger service.

A transaction record has three fields: timestamp, user_id, and delta_amount. delta_amount can be positive or negative and represents how that user's balance changes during the day. All amounts are integers.

  1. Given a list of transaction records for a single day, compute each user's end-of-day net balance, assuming every user's starting balance is 0.
  2. Using the resulting balances, generate a settlement plan with the minimum possible number of transfers so that every user's final balance becomes 0. A user with a negative balance must pay money, and a user with a positive balance must receive money. Each settlement transfer should be represented as (from_user, to_user, amount) .

Notes:

  • Users whose balance is 0 do not need to appear in the settlement plan.
  • You may assume the sum of all balances is 0.
  • For the exact-minimum settlement part, assume the number of users with non-zero balance is small enough to permit an exponential-search solution if needed.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Affirm•More Software Engineer•Affirm Software Engineer•Affirm Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.