FastPrepOptimal Account Balancing
Problems/Optimal Account Balancing

Optimal Account Balancing

Pinterest logoPinterest● HardFULLTIMEPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Pinterest onsite interview. The report names this well-known task but does not give the statement or the constraints. Our version is about 90% the same as the reported question.

You are given a list transactions. Each transaction [from, to, amount] means that person from paid amount on behalf of person to.

After all transactions, people may transfer money directly between one another to settle every net balance. One settlement transfer may use any positive amount between any two people.

Return the minimum number of settlement transfers needed so that every person's net balance becomes zero.

Function

minTransfers(transactions: int[][]) → int

Examples

Example 1

transactions = [[0,1,10],[2,0,5]]return = 2

The net balances are -5 for person 0, +10 for person 1, and -5 for person 2. Two transfers are necessary and sufficient.

Example 2

transactions = [[0,1,10],[1,0,1],[1,2,5],[2,0,5]]return = 1

After combining all activity, only two nonzero net balances remain, with equal magnitude and opposite signs. One transfer settles them.

Constraints

  • 1 <= transactions.length <= 8
  • Each transaction contains exactly three integers [from, to, amount].
  • 0 <= from, to <= 20
  • from != to
  • 1 <= amount <= 100

More Pinterest Onsite Interview questions

  • Minimum Bus Routes to a DestinationPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Delete and Compact a Forest SubtreePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Filter Pins by Excluded IDsONSITE INTERVIEW · Seen Oct 2026
  • Top-Scoring Items in a Time WindowONSITE INTERVIEW · Seen Oct 2026
  • Escape Room LeaderboardPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Policy Violation Set ChecksONSITE INTERVIEW · Seen Sep 2026
  • Shortest Sequence of Source SubsequencesONSITE INTERVIEW · Seen Sep 2026
  • Insert Addition and Multiplication OperatorsONSITE INTERVIEW · Seen Sep 2026
  • Unique Active Pins by Time SegmentONSITE INTERVIEW · Seen Sep 2026
  • Coin ChangeONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • Word Break IIAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Optimal Account BalancingSalesforce · PHONE SCREENSalesforce interview questions
  • Word Break IIBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Minimum Account SettlementsRippling · PHONE SCREENRippling interview questions
  • Validate a Mahjong Hand PartitionDuolingo · PHONE SCREENDuolingo interview questions
  • Optimal Account BalancingVirtu Financial · OAVirtu Financial interview questions
  • Max Points on a LineLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
  • Sudoku Puzzle SolverConfluent · PHONE SCREEN · ONSITE INTERVIEWConfluent interview questions
  • Max Points on a LineUber · PHONE SCREENUber interview questions
  • Jump Game IVZomato / Eternal · ONSITE INTERVIEWZomato / Eternal interview questions

Pinterest interview experiences

  • Pinterest Experienced MLE Phone Screen: 1 Experience
All Pinterest interview questionsSee Pinterest hiring insights
Saved
class Solution {
    public int minTransfers(int[][] transactions) {
        // Write your code here.
    }
}
Checking account…