Card Transaction Stream
Updated
Problem statement
A card service holds several credit cards. Each card starts with a balance, the amount it can still spend. Transactions then come in one at a time, and each one is approved or declined as soon as it arrives.
cards[i] has the form "cardId balance": a card and its starting balance. transactions[j] has the form "charge cardId amount" or "payment cardId amount".
- A charge goes through only if
cardIdbelongs to one of the cards andamountis at most that card's current balance. Then the balance goes down byamount. A declined charge leaves the balance as it was. - A payment goes through if
cardIdbelongs to one of the cards, and it raises that card's balance byamount. - Any transaction that names an id missing from
cardsis declined.
Go through the transactions in order. Return a boolean array where position j is true exactly when transactions[j] went through.
Function
approveTransactions(cards: String[], transactions: String[]) → boolean[]Examples
Example 1
cards = ["c1 300","c2 50"]transactions = ["charge c1 120","charge c2 80","charge c1 180","charge c1 1"]return = [true,false,true,false]c1starts at 300. The charge of 120 fits, leaving 180.c2has only 50, so the charge of 80 is declined andc2stays at 50.- The charge of 180 on
c1equals its balance, which is allowed, so it is approved andc1drops to 0. - Now even a charge of 1 is too much for
c1, so it is declined.
Example 2
cards = ["visa9 40"]transactions = ["charge visa9 70","payment visa9 50","charge visa9 70","charge visa9 25"]return = [false,true,true,false]- A charge of 70 is more than the starting 40, so it is declined.
- The payment of 50 is approved and raises the balance to 90.
- The same charge of 70 now fits, leaving 20.
- The last charge of 25 is more than 20, so it is declined.
Example 3
cards = ["a 10","b 0"]transactions = ["payment zz 100","charge b 5","payment b 5","charge zz 1","charge b 5","charge a 10"]return = [false,false,true,false,true,true]zzis not one of the cards, so both transactions that name it are declined: the payment of 100 and, later, the charge of 1. The payment does not create a card.bstarts with nothing, so its first charge of 5 is declined.- After the payment of 5, the same charge leaves
bat 0 and is approved. aspends its whole 10 in one approved charge.
Constraints
1 <= cards.length <= 1000and1 <= transactions.length <= 2000- Every id, in
cardsor intransactions, is made of 1 to 12 characters froma-zand0-9. No id appears twice incards. - Each starting balance lies in
[0, 10^9]and eachamountin[1, 10^9]. - Parts inside a string are separated by one space, and a number never begins with 0 unless it is 0 itself.
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
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- In-Memory Vault File SystemHarvey · ONSITE INTERVIEWHarvey interview questions
- Feature Flag Evaluation EngineCresta · ONSITE INTERVIEWCresta interview questions
- Account Scheduler - Availability and AcquireStripe · ONSITE INTERVIEWStripe interview questions
- In-Memory Directory and File OperationsSquarepoint Capital · ONSITE INTERVIEWSquarepoint Capital interview questions
- In-Memory Spreadsheet ValuesRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Return Every Matching DecryptionDuolingo · PHONE SCREENDuolingo interview questions
- Parcel Event TrackingAirbnb · OAAirbnb interview questions
- Reference-Counted Deduplicating File SystemCitadel · PHONE SCREENCitadel interview questions
- Design In-Memory File SystemSnowflake · PHONE SCREENSnowflake interview questions
Capital One interview 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
- Capital One TDP Agentic Power Day: 25 Experiences (Part 1 of 2)