FastPrepTransaction Event Store
Problems/Transaction Event Store

Transaction Event Store

Capital One logoCapital One● MediumINTERNONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: A 2026 report from a Capital One intern Super Day lists a question about keeping track of transactions in code. It gives no details beyond that.

So every rule here is a practice choice. Each event has an id, an account, a time and an amount, and events can arrive out of time order. A repeated id is ignored. A time-range query includes both of its ends and sorts by time, then by id. An account with no events has a total of 0. The calls come as a list of operations, and each call gets back one list of strings.

The judged task matches the report at about 40%.

A card team keeps a log of transaction events. Each event carries four values: an eventId, the accountId it belongs to, the timestamp when it happened, and an amount. Events reach the log in no particular time order, and the log starts with no events.

The rows of operations are calls made to the log, in order. Handle each call like this:

  • ["RECORD", eventId, accountId, timestamp, amount] adds the event to the log and answers true. Event ids are unique across the whole log, not just within one account. When this eventId is already in the log, nothing is added, the logged event keeps its original values, and the answer is false.
  • ["EVENTS", accountId, startTime, endTime] lists the ids of that account's logged events with startTime <= timestamp <= endTime. Earlier timestamps come first. For equal timestamps, the id that is smaller as a string comes first (see the rule below). With no matching events the list is empty.
  • ["TOTAL", accountId] answers the sum of the amounts of that account's logged events. An account with no logged events has a total of 0.

Ids are compared as plain strings. Find the first position where the two ids differ: the id with the smaller character there comes first, and the digits 0 to 9 are smaller than the letters a to z. If one id is the beginning of the other, the shorter id comes first. So "b10" comes before "b7", and "e10" comes before "e100".

Write the answers into a list with one entry per call, in call order. Each entry is a list of strings: for EVENTS it is the id list itself, and for RECORD and TOTAL it holds the single answer written as a string, like ["false"] or ["0"].

Function

processTransactionEvents(operations: String[][]) → String[][]

Examples

Example 1

operations = [["RECORD","t1","acct1","300","500"],["RECORD","t2","acct2","100","200"],["RECORD","t3","acct1","100","1500"],["RECORD","t1","acct2","50","999"],["EVENTS","acct1","0","1000"],["TOTAL","acct1"],["TOTAL","acct2"],["EVENTS","acct2","150","400"]]return = [["true"],["true"],["true"],["false"],["t3","t1"],["2000"],["200"],[]]
  • The first three events are new, so each RECORD returns true. Event t3 arrives after t1 but happened earlier, at time 100.
  • The fourth call reuses the id t1. It is ignored and returns false, even though its account and amount are different.
  • acct1 has t3 at time 100 and t1 at time 300, so the list is ["t3","t1"].
  • The totals are 1500 + 500 = 2000 for acct1 and 200 for acct2. The ignored call added nothing.
  • acct2 has one event, at time 100, which is outside [150, 400], so the last result is empty.

Example 2

operations = [["RECORD","b7","acc","60","10"],["RECORD","b10","acc","60","20"],["RECORD","a5","acc","120","30"],["EVENTS","acc","60","120"],["EVENTS","acc","61","119"],["TOTAL","zzz"],["TOTAL","acc"]]return = [["true"],["true"],["true"],["b10","b7","a5"],[],["0"],["60"]]
  • b7 and b10 both happened at time 60. Compared character by character, "b10" comes before "b7" because '1' comes before '7'. Then comes a5 at time 120.
  • Both ends of the range count, so [60, 120] includes all three events. [61, 119] includes none of them.
  • zzz has no events, so its total is 0. The total for acc is 10 + 20 + 30 = 60.

Constraints

  • 1 <= operations.length <= 1000
  • Every operation row uses one of the three call forms shown above.
  • eventId and accountId have 1 to 10 characters, and each character is a lowercase English letter or a digit.
  • timestamp, startTime and endTime are whole numbers from 0 to 10^9, and startTime <= endTime.
  • amount is a whole number from 1 to 10^9.
  • Every number is written in base 10 without leading zeros.

More Capital One problems

  • Digit-Coded Card ValidationONSITE INTERVIEW · Seen Nov 2026
  • Rank Football TeamsOA · Seen Oct 2026
  • Count Subarrays Matching a Comparison PatternOA · Seen Oct 2026
All Capital One interview questionsSee Capital One hiring insights
Saved
public String[][] processTransactionEvents(String[][] operations) {
    // Write your code here.
}
Checking account…