FastPrepBank Accounts With Undo
Problems/Bank Accounts With Undo

Bank Accounts With Undo

Capital One logoCapital One● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: An April 2021 report from a Capital One technology development program candidate lists a design question about a banking system that can take deposits, take withdrawals, move money to and from accounts, and undo.

The report gives no rules, input format or limits. Here accounts start at zero and come into being when they are used, a withdrawal or transfer that would overdraw an account fails, UNDO reverses the latest successful step that has not been reversed yet, and failed commands, UNDO and BALANCE are never reversed. There are up to 2000 commands. These are practice choices.

The judged task matches the report at about 65%.

A bank keeps one balance per account. There is no account setup: an account that has never been used holds 0. Run the entries of commands in order. Each one is:

  • "DEPOSIT id amount": add amount to the account and return "OK".
  • "WITHDRAW id amount": if the balance is at least amount, take it out and return "OK". Otherwise return "FAILED" and change nothing.
  • "TRANSFER from to amount": if from and to are different accounts and from holds at least amount, move amount from from to to and return "OK". Otherwise return "FAILED" and change nothing.
  • "UNDO": reverse the most recent DEPOSIT, WITHDRAW or TRANSFER that succeeded and has not been reversed yet, and return "OK". If there is none, return "NOTHING". A command that returned "FAILED" is never reversed, and neither is an UNDO.
  • "BALANCE id": return the balance of the account as a decimal string. It changes nothing and is never reversed.

Return one string per command, in the order of commands.

Function

runBankCommands(commands: String[]) → String[]

Examples

Example 1

commands = ["DEPOSIT ann 100","WITHDRAW ann 30","WITHDRAW ann 500","TRANSFER ann bob 50","BALANCE ann","BALANCE bob","UNDO","BALANCE ann","BALANCE bob","UNDO","BALANCE ann","UNDO","BALANCE ann"]return = ["OK","OK","FAILED","OK","20","50","OK","70","0","OK","100","OK","0"]

After the first four commands ann holds 20 and bob holds 50; the withdrawal of 500 fails and is not remembered. The first UNDO reverses the transfer and restores both balances (70 and 0). The next UNDO reverses the withdrawal of 30, not the failed one, so ann is back to 100; the last one removes the deposit and leaves 0. BALANCE commands are never reversed.

Example 2

commands = ["UNDO","DEPOSIT a 10","UNDO","UNDO","BALANCE a","DEPOSIT a 5","WITHDRAW a 9","TRANSFER a a 1","UNDO","BALANCE a","UNDO","UNDO","BALANCE a"]return = ["NOTHING","OK","OK","NOTHING","0","OK","FAILED","FAILED","OK","0","NOTHING","NOTHING","0"]

The first UNDO has nothing to reverse. After DEPOSIT a 10, an UNDO takes it back, and the UNDO after that finds nothing: an undo is not a step that can itself be reversed or repeated, so the balance stays 0. Later the withdrawal of 9 is refused (only 5 is there) and so is the transfer of an account to itself. Neither is remembered, so the next UNDO reverses the deposit of 5, and the two after it find nothing.

Example 3

commands = ["DEPOSIT x 40","TRANSFER x y 40","WITHDRAW y 40","BALANCE x","BALANCE y","UNDO","BALANCE y","UNDO","BALANCE x","BALANCE y","TRANSFER y x 41","BALANCE y"]return = ["OK","OK","OK","0","0","OK","40","OK","40","0","FAILED","0"]

The transfer moves all 40 from x to y, which is allowed (a balance may reach 0), and y did not exist before it. Withdrawing 40 from y is allowed too, so both balances are 0. The first UNDO gives y its 40 back; the second reverses the transfer, so x holds 40 again and y holds 0. The transfer of 41 from y fails.

Constraints

  • 1 <= commands.length <= 2000
  • Each command has one of the five forms above, with single spaces, and is 4 to 28 characters long.
  • Every account id is 1 to 6 lowercase letters or digits, and every amount is a whole number from 1 to 10^4.

More Capital One Onsite Interview questions

  • Digit-Coded Card ValidationONSITE INTERVIEW · Seen Nov 2026
  • Sort ColorsONSITE INTERVIEW · Seen Oct 2026
  • Virtual Card Transaction ValidatorONSITE INTERVIEW · Seen Oct 2026
  • Banking System with Top ActivityONSITE INTERVIEW · Seen Sep 2026
  • Transaction Event StoreONSITE INTERVIEW · Seen Jul 2026
  • Shortest Path in an Unweighted GraphONSITE INTERVIEW · Seen Jul 2026
  • Duplicate Transactions Within 60 SecondsONSITE INTERVIEW · Seen May 2026
  • LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen May 2026
  • Cashback TrackerONSITE INTERVIEW · Seen Nov 2025
  • Reverse a StringOA · ONSITE INTERVIEW · Seen Oct 2025

Similar questions at other companies

  • Code Editor FoldingJane Street · ONSITE INTERVIEWJane Street interview questions
  • Undo and Redo Command HistoryNetflix · ONSITE INTERVIEWNetflix interview questions
  • Text Document HistoryNotion · PHONE SCREEN · ONSITE INTERVIEWNotion interview questions
  • Transactional In-Memory RedisHashiCorp · ONSITE INTERVIEWHashiCorp interview questions
  • Key-Value Store with Nested TransactionsRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • Implement a Queue Using Two StacksAmazon · ONSITE INTERVIEW
  • Billing Log with Undo and RedoReddit · PHONE SCREENReddit interview questions
  • Multiline Text Editor with Cursor MovementDatologyAI · PHONE SCREEN
  • Layer History with Batch Undo and RedoFigma · OA · PHONE SCREENFigma interview questions
  • Undo/Redo Timeline State EngineKickdrum · OA

Capital One interview experiences

  • Capital One Coding OA Questions: 3 Experiences
  • Capital One Experienced Engineer Power Day and OA: 6 Experiences
  • Capital One New Grad OA Questions: 14 Experiences (Part 2 of 2)
  • Capital One TDP Agentic Round (AI Coding): 7 Experiences
  • Capital One SWE Power Day, Level Not Reported: 6 Experiences
  • Capital One TIP Intern OA and Power Day: 13 Experiences
All Capital One interview questionsSee Capital One hiring insights
Saved
class Solution {
    public String[] runBankCommands(String[] commands) {
        // Write your code here.
    }
}
Checking account…