For All Intents And Purposes Part 2 - Change Is Good! π
Updated
Problem statement
π Hi there! The description you are currently reading is just 2nd part of the problem set. It is highly recommended to read ALL THE PARTS before coding as parts may build on top of each other π³
- For All Intents And Purposes Part 1 - Initilizing the System ποΈ
- For All Intents And Purposes Part 2 - Change Is Good! π
- For All Intents And Purposes Part 3 - Accepting Failure π
- For All Intents And Purposes Part 4 - Timing Matters β°
The initial version of our system looks good ππ! But it turns out merchants also need to be able to update the amount of initialized Payment Intents. This happen if a customer begins to check out but then decides to change the items in their shopping cart π and thus the amount of the payment. Let's add that the our system π»!
All commands from Part 1 (INIT, CREATE, ATTEMPT and SUCCEED) still work exactly as described there. The output is also the same as in Part 1: one string "<merchant_id> <balance>" for every initialized merchant, sorted by merchant ID. IDs are compared as plain strings, character by character (so m10 comes before m2).
Commands
Your system should support an additional command for updaing a Payment Intent.
UPDATE <payment_intent_id> <new amount>
- Update the monetary amount of an existing Payment Intent in the REQUIRES_ACTION state. This does not transition the state of the Payment Intent.
- If no Payment Intent with the given identifier exists, or if the Payment Intent is not in the REQUIRES_ACTION state, or if the new amount is negative, this mommand should do nothing.
Function
forAllIntentsAndPurposes2(commands: String[]) β String[]Examples
Example 1
commands = ["INIT m1 0", "CREATE p1 m1 50", "UPDATE p1 100", "ATTEMPT p1", "SUCCEED p1"]return = ["m1 100"]While the Payment Intent p1 was initially created with an amount of 50, this was then updated to 100 before being attempted then succeeded. Therefore, merchant m1 has a balance of 100 after all commands have been processed.
Constraints
1 β€ commands.length β€ 10^4- Each command is one of
INIT,CREATE,ATTEMPT,SUCCEEDorUPDATE, written exactly as described, with single spaces between its parts. - Merchant IDs and Payment Intent IDs have
1to10characters, and every character is a lowercase English letter or a digit. 0 β€ starting_balance β€ 10^5-10^5 β€ amount, new amount β€ 10^5- Every number is a plain decimal integer (a minus sign only for negative numbers, no leading zeros).
More Stripe interview questions
- Merchant Payout Scheduler, Part 2: Per-Merchant SchedulesPHONE SCREEN Β· Seen Nov 2026
- Financial Account LedgerOA Β· PHONE SCREEN Β· Seen Nov 2026
- Business Account KYC Verification β Parts 1β5PHONE SCREEN Β· Seen Nov 2026
- Chat Billing CalculationOA Β· Seen Nov 2026
- Render a Task Tree from CSV RowsPHONE SCREEN Β· ONSITE INTERVIEW Β· Seen Nov 2026
- Deployment Window SchedulerOA Β· Seen Nov 2026
- Invoice / Payment ReconciliationPHONE SCREEN Β· ONSITE INTERVIEW Β· Seen Nov 2026
- Linked Merchants Within Two HopsPHONE SCREEN Β· Seen Nov 2026
- Asynchronous Event ProcessingOA Β· Seen Nov 2026
- Portfolio Valuation, Part 1PHONE SCREEN Β· Seen Nov 2026
Similar questions at other companies
- Student and Course EnrollmentWells Fargo Β· OAWells Fargo interview questions
- Overheat Prevention ControllerOptiver Β· OAOptiver interview questions
- LFU CacheSnowflake Β· OA Β· ONSITE INTERVIEWSnowflake interview questions
- Corporate Card Expense RulesRippling Β· OA Β· PHONE SCREEN Β· ONSITE INTERVIEWRippling interview questions
- Least Recently Used CacheMicrosoft Β· OA Β· PHONE SCREEN Β· ONSITE INTERVIEWMicrosoft interview questions
- Parcel Attribute Store with TTLAirbnb Β· OAAirbnb interview questions
- Process Banking OperationsVercel Β· OA
- Four-Level Banking System with Scheduled PaymentsZipRecruiter Β· OAZipRecruiter interview questions
- Expiring Authentication Token ManagerIBM Β· OAIBM interview questions
- LFU CacheArista Networks Β· OAArista Networks interview questions