FastPrepContainer Ledger with Trades
Problems/Container Ledger with Trades

Container Ledger with Trades

Flexport logoFlexport● EasyFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported as the coding round of a Flexport onsite interview for a full-time software engineering role. The report sums up the coding task in one line: a ledger that tracks the shipping containers held by customers who trade them.

The report gives no interface, no examples and no limits, so we chose every rule that changes an answer: a balance is the number of containers a customer holds, there is one kind of container, and a trade carries no price; the ledger is a list of text operations run in order, with one integer result each; ADD is our way for containers to enter the ledger and returns the customer's new balance; every customer starts at 0 and exists from the first operation that names it; a trade whose seller holds fewer containers than asked is refused as a whole, changes nothing and returns 0, while a trade that moves containers returns 1; the operation strings, the limits and all the examples are ours too. The system design question from the same interview is not part of this problem.

Our version is about 60% the same as the reported question.

Given a list of operations on a container ledger, run them in order and return an array with one integer result per operation.

The ledger records how many shipping containers each customer holds. This number is the customer's balance. Every customer starts with a balance of 0, including a customer who appears for the first time in any operation.

Each string in operations has one of these three forms, with parts separated by single spaces. <customer>, <seller> and <buyer> are customer names, and <count> is a positive whole number.

  • "ADD <customer> <count>": <customer> receives <count> new containers. The result is the customer's balance after the addition.
  • "TRADE <seller> <buyer> <count>": <seller> gives <count> containers to <buyer>. If the seller's balance is at least <count>, the seller's balance goes down by <count>, the buyer's goes up by <count>, and the result is 1. Otherwise the trade is refused: no balance changes, not even in part, and the result is 0.
  • "BALANCE <customer>": the result is the customer's current balance, which is 0 for a customer not seen before.

Every result includes the effect of all earlier operations.

Function

containerLedger(operations: String[]) → int[]

Examples

Example 1

operations = ["ADD acme 10","ADD nova 4","TRADE acme nova 3","ADD nova 2","BALANCE acme","BALANCE nova"]return = [10,4,1,9,7,9]

The two ADD operations give acme 10 containers and nova 4. The trade moves 3 from acme to nova, so each has 7. Adding 2 more gives nova 9.

Example 2

operations = ["ADD acme 5","TRADE acme nova 6","BALANCE acme","TRADE acme nova 5","BALANCE acme","BALANCE nova"]return = [5,0,5,1,0,5]

acme has only 5 containers, so the trade of 6 is refused and nothing moves, not even part of it. A trade of exactly 5 goes through and leaves acme with 0.

Example 3

operations = ["BALANCE zenith","TRADE zenith acme 1","ADD acme 2","TRADE acme zenith 2","TRADE zenith nova 1","ADD acme 3","BALANCE zenith","BALANCE nova","BALANCE acme"]return = [0,0,2,1,1,3,1,1,3]

zenith has not appeared before, so its balance is 0 and its trade is refused. After it receives 2 containers from acme, it can trade 1 of them to nova, a customer seen for the first time.

Constraints

  • 1 <= operations.length <= 1000
  • Each operations[i] has one of the three forms above, with single spaces between its parts.
  • Each customer name has 1 to 10 characters, each a lowercase letter or a digit.
  • In each TRADE, <seller> and <buyer> are different customers.
  • Each <count> is a whole number from 1 to 10^6, written without leading zeros.
  • Every balance stays at most 10^9.

More Flexport interview questions

  • Choose the Next Hidden-Word GuessONSITE INTERVIEW · Seen Jul 2026
  • Apply Operations to Make a String EmptyPHONE SCREEN · Seen Nov 2026
  • Max Area of Island Without Changing the GridPHONE SCREEN · Seen Nov 2026
  • Count Good SubsequencesOA · Seen Jun 2024
  • Distinct MovesOA · Seen Jun 2024
  • Hotspot ConnectionsOA · Seen Jun 2024
  • Throw The BallOA · Seen Jun 2024
  • Matrix TraversalOA · Seen Feb 2024
  • Collect PointsOA · Seen Feb 2024
  • Malware SpreadOA · Seen Feb 2024

Similar questions at other companies

  • Account Balance Manager Part 2 - Reject OverdraftsStripe · ONSITE INTERVIEWStripe interview questions
  • Card Transaction StreamCapital One · ONSITE INTERVIEWCapital One interview questions
  • Route Pattern MatcherGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • File System Shell CommandsHarvey · ONSITE INTERVIEWHarvey interview questions
  • Feature Flags with Rules, Dependencies and ExposurePerplexity AI · ONSITE INTERVIEWPerplexity AI interview questions
  • Generate Word Guess FeedbackAtlassian · ONSITE INTERVIEWAtlassian interview questions
  • Stable Unique Column RenamesMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Most Frequent Call Path in Interleaved LogsRoblox · ONSITE INTERVIEWRoblox interview questions
  • Dictionary Records to an Editable XML TreeSnap Inc. · ONSITE INTERVIEWSnap Inc. interview questions

Interview reports that mention this question

  • Flexport interviews · 2026
All Flexport interview questionsSee Flexport hiring insights
Saved
class Solution {
    public int[] containerLedger(String[] operations) {
        // Write your code here.
    }
}
Checking account…