FastPrepOut-of-Order Bank Ledger Balances
Problems/Out-of-Order Bank Ledger Balances

Out-of-Order Bank Ledger Balances

Perplexity AI logoPerplexity AI● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: You keep a bank ledger whose transaction records can show up out of time order, and answer what an account's balance was at a given moment. This comes from a Perplexity online assessment the candidate took after a recruiter reached out. It asked for a banking system with account lookups and out-of-order inserts, and its final part resembled a time-keyed key-value store.

The report describes the parts only in passing, with no operations, formats, examples or limits. We chose these: two operations as integer rows (insert a signed amount for an account at a time; ask an account's balance at a time). A balance counts only records already inserted with time at most the asked time. Unknown accounts have balance 0 and balances may go negative. Answers are listed in query order as 64-bit integers. We left out the earlier assessment parts that the report does not describe. The limits and examples are ours.

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

A bank keeps a ledger of transaction records for its accounts. Records do not arrive in time order: a record with an early time may be inserted after records with later times. Process operations in the given order. Each operation is one of:

  • [0, account, time, amount]: insert a record that changes account's balance by amount (negative for a withdrawal) at time.
  • [1, account, time, 0]: answer the balance of account at time, which is the sum of the amounts of all records for that account inserted before this query whose time is at most time.

An account with no such records has balance 0, and balances may be negative. Records with the same time all count. Return the answers to the queries in the order the queries appear. Balances can exceed the 32-bit integer range.

Function

processLedger(operations: int[][]) → long[]

Examples

Example 1

operations = [[0,7,10,100],[0,7,30,-40],[1,7,20,0],[1,7,30,0],[0,7,5,25],[1,7,20,0],[1,9,100,0]]return = [100,60,125,0]
  • Account 7 records +100 at time 10 and -40 at time 30.
  • Balance of 7 at time 20: only the record at 10 counts, so 100. At time 30: 100 - 40 = 60.
  • A late record +25 arrives with the earlier time 5. It changes history: the balance at time 20 is now 25 + 100 = 125.
  • Account 9 has no records, so its balance is 0.

Example 2

operations = [[0,1,50,10],[0,1,50,5],[1,1,49,0],[1,1,50,0]]return = [0,15]

Two records share time 50. At time 49 neither counts (balance 0); at time 50 both count (10 + 5 = 15).

Example 3

operations = [[1,3,0,0],[0,3,0,-20],[1,3,1000000000,0]]return = [0,-20]

The first query comes before any record is inserted, so it answers 0. After the withdrawal of 20 at time 0, the balance at any later time is -20; balances may go negative.

Constraints

  • 1 <= operations.length <= 4000
  • Every operation has exactly four integers.
  • A record is [0, account, time, amount] with 1 <= account <= 10^9, 0 <= time <= 10^9 and -10^6 <= amount <= 10^6.
  • A query is [1, account, time, 0] with 1 <= account <= 10^9 and 0 <= time <= 10^9.
  • At least one operation is a query.

More Perplexity AI interview questions

  • Feature Flags with Rules, Dependencies and ExposureONSITE INTERVIEW · Seen Nov 2026
  • In-Memory Filesystem CommandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Resource Reconciler: Plan and Apply CreatesPHONE SCREEN · Seen Nov 2026
  • Sort Topic Names by Prefix and NumberONSITE INTERVIEW · Seen Oct 2026
  • Agent Task Dependency TrackerPHONE SCREEN · Seen May 2026
  • LLM Provider Pool FailoverPHONE SCREEN · Seen Aug 2025

Similar questions at other companies

  • Time Based Key-Value StoreCoalition · OA
  • Time Based Key-Value StoreAtlassian · OAAtlassian interview questions
  • In-Memory Database with Historical Field LookupMeta · OAMeta interview questions
  • Banking System with Historical SnapshotsCoinbase · OACoinbase interview questions
  • Snapshot Map with Sparse Version HistorySnorkel AI · PHONE SCREEN
  • Time-Based Key-Value StoreOracle · PHONE SCREEN · ONSITE INTERVIEWOracle interview questions
  • Time-Based Key-Value StoreCockroach Labs · PHONE SCREEN · ONSITE INTERVIEW
  • Time Map with Sum and AverageConfluent · PHONE SCREENConfluent interview questions
  • Structured Log Stream with QueriesOpenAI · PHONE SCREENOpenAI interview questions
  • Time-Indexed Key-Value StoreTogether AI · ONSITE INTERVIEW
All Perplexity AI interview questionsSee Perplexity AI hiring insights
Saved
class Solution {
    public long[] processLedger(int[][] operations) {
        // Write your code here.
    }
}
Checking account…