For All Intents And Purposes Part 1 - Initializing the System ποΈ
See Stripe hiring insights
π Hi there! The description you are currently reading is just 1st 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 π³
Background
Stripe processes billions of dollars of payments to businesses every day through dozens of different payment methods like cards, bank debits, and even papaer cheques.
We don't want merchants (the businesses who use Stripe to accept peyments) to have to worry about the details for each specific payment method. For example, for many payment methods, payments are not completed instantly and can take a few days to process and be confirmed or fail, while others are processed much more quickly. Stripe abstracts this payment flow with a simple state machine object called a Payment Intent.
Today, imagine you are an engineer working at Stripe in its early days. You will implement a system that handles the creation and management of these Payment Intens, helping merchants easily setup and accept payments from customers.
Please read all instructions for each part before you begin coding for that part.
What is a Payment Intent?
A Payment Intent tracks a payment through its flow from initilization to processing to confirmation. We model this flow as a state machine: an abstract object that can exist in one of a number of states and transition between states.
A Payment Intent stores information like the merchant receiving the peyment and the monetary amount. It also should keep track of its state, which can be one of three values
π The initial state of a Payment Intent upon creation. Can transition to PROCESSING.
π The customer has attempted to pay but the attempt has not yet succeeded or failed. Can transition to either REQUIRES_ACTION or COMPLETED
π The attempt to pay succeeded and the Payment Intent amount was added to the merchant's balance.
You Task
You will implement a function that executes a chronologically ordered list of commands to create and manage Payment Intents for different merchants and then returns the account balances for each merchant after executing all commands.
Input
You will receive a chronologically ordered list of commands in the form ['INIT m1 0', 'CREATE p1 m1 100'] where each command is a single string. You will also receive the part number, corresponding to the pairs in the problem description. The commands you need to support are decribed below.
Output
A list of merchant balances in the form ['m1 100', 'm2 200'] representing the balance for each merchant after executing all commands. The list should be sorted by merchant ID in ascending alphabetical order.
Part 1: Good Intentions
To build the initial version of our system, we will support a few basic commands for initializing a merchant, creating a Payment Intent, attempting a Payment Intent, and succeeding a Payment Intent.
Commands
For this part, your system should handle the following commands -
INIT <merchant_id> <starting_balance>
CREATE <payment_init_id> <merchant_id> <amount>
ATTEMPT <payment_init_id>
SUCCEED <payment_init_id>
π³βqΛββ ππ«§πΌ ΛΒ°Credit to Rachelα₯«α‘.
commands = ["INIT m1 0", "INIT m2 10", "CREATE p1 m1 50", "ATTEMPT p1", "SUCCEED p1", "SUCCEED p1", "CREATE p2 m2 100", "ATTEMPT p2"] return = ["m1 50", "m2 10"]
π«Ά
- Request Routing SystemOA Β· Seen May 2026
- Email Log Processing, Grouping, and SortingOA Β· Seen May 2026
- Generate Available Time SlotsPHONE SCREEN Β· Seen Apr 2026
- Chat Billing CalculationSeen Mar 2026
- Process List of CommandsSeen Dec 2024
- Card Range Obfuscation Part 2 (ML Eng :)Seen Nov 2024
- Card Range Obfuscation Part 3 (ML Eng :)Seen Nov 2024
- Card Range Obfuscation Part 4 (ML Eng :)Seen Nov 2024
public String[] forAllIntentsAndPurposes(String[] commands) {
// write your code here
}