FastPrepFor All Intents And Purposes Part 4 - Timing Matters ⏰
Problems/For All Intents And Purposes Part 4 - Timing Matters ⏰

For All Intents And Purposes Part 4 - Timing Matters ⏰

Stripe logoStripe● MediumINTERNNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Approximately 85% matches the reported exercise. The original internship photo supplies the timed refund rules, including the inclusive deadline and missing, zero, and negative timeout policies; its example contents and earlier parts are not visible. Earlier command rules are corroborated by a separate report. Command-count, numeric-token and merchant-count bounds and the ungraded per-part practice interface are supplied for this exercise.

Special thanks: Rachel shared this problem.

🐝 Hi there! The description you are currently reading is just 4th part of the problem set. It is highly recommended to read ALL THE 4 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 ⏰

Last month, we received the new Payment Intent system you built πŸ‘, and merchants have been LOVING how simple it makes accepting payments. Congratulations πŸŽ‰!

However, numerous merchants have requested that we augment our refund functionality by letting merchants specify a refund timeout policy: the amount of time after a payment succeeds that refunds are permitted. For example, one merchant, LlmaCorp, only wants to accept refunds within 15 days of a payment succeeding. Being able to return a llama afte 15 days would be absurd after all.

Let's add this functionality to our system, which means we will need to change the format of our commands to handle timing πŸ’ͺ.

Timestamps

  • All commands will now have an integer timestamp in front. For example, intead of SUCCEED <pi_id>, you will now receive<timestamp>SUCCEED <pi_id>
  • You can assume that the timestamps will always be integers (representing a unit of time) and that the timestamps of the list of commands will be strictly increasing

Merchant Refund Timeout Limit

  • The INIT command that initializes a merchant will now have an optional third argument specifying the merchant's refund timeout limit. The new specification is -

πŸ‘‰ <timestamp> INIT <merchant_id> <starting_balance> <refund_time_out_limit>

  • If a merchant has a refund_timeout_limit of n, and succeeds a Payment Intent (with the SUCCEED command) at timestamp t, then the timestamp of a REFUND command must be no greater than t + n, otherwise the refund should no succeed.
  • iF A refund_timeout_limit is not specified during merchant initialization, there is no refund time limit, a a refund should succeed regardless how much time has passed since Payment Intent confirmation. A reund_timeout_limit of 0 means no refunds should be accepted ever, and a negative refund_timeout_limit should be ignore (meaning all refunds should be accepted)

Inherited payment-intent commands

This timed part retains the preceding command rules. Every command below has a strictly increasing integer timestamp prefix.

  • INIT merchant_id starting_balance [refund_timeout_limit] creates a merchant only when its ID does not exist.
  • CREATE intent_id merchant_id amount creates a new intent in REQUIRES_ACTION only when the intent ID is unused, the merchant exists, and the amount is nonnegative.
  • UPDATE intent_id new_amount changes a nonnegative amount only in REQUIRES_ACTION, without changing the state.
  • ATTEMPT intent_id changes REQUIRES_ACTION to PROCESSING.
  • SUCCEED intent_id changes PROCESSING to COMPLETED, records that command's timestamp, and credits the merchant once.
  • FAIL intent_id changes PROCESSING back to REQUIRES_ACTION, allowing an update or retry.
  • REFUND intent_id debits a completed, previously unrefunded intent once when the merchant's timeout permits it. A rejected refund changes nothing. A successful refund retains COMPLETED and records a separate refunded flag.

Commands with missing identities or invalid state transitions do nothing. Return one string merchant_id balance for every initialized merchant in ascending lexicographic ID order. The graded method is forAllIntentsAndPurposes4(commands); it always processes timed Part 4 commands.

Bounds

For this exercise, assume IDs contain ASCII letters, digits, or underscores and have 1–50 characters; each command uses its documented syntax with single ASCII spaces. There are 0–1,000 commands and at most 500 distinct initialized merchants. Timestamps are integers in 0–1,000,000,000 and strictly increase. Starting balances, amounts, updated amounts, and specified timeout limits are integers in -1,000,000,000–1,000,000,000. Numeric tokens use canonical decimal notation: 0, a nonzero-leading sequence of decimal digits, or a minus sign followed by a nonzero-leading sequence for a negative number. Leading zeros, plus signs, and -0 are not valid input. Negative amounts remain valid command arguments but are rejected by CREATE or UPDATE. Accumulated balances require signed 64-bit arithmetic.

Ungraded follow-up: one implementation for all four parts

A variation uses a command list plus a part selector. Use processPaymentPart(commands, part), with part from 1 to 4, to expose that variation without changing the graded method. Parts 1–3 omit timestamp prefixes. Part 1 permits INIT, CREATE, ATTEMPT, and SUCCEED; Part 2 adds UPDATE; Part 3 adds FAIL and REFUND with no timeout; Part 4 adds the timestamp and merchant policy. Each invocation starts a fresh system and returns the same sorted final-balance format. All bounds, including the maximum of 500 distinct initialized merchants, apply to every part. Its input commands use only that part's documented operations. Complete implementations are included in both editorial approaches.

Function

forAllIntentsAndPurposes4(commands: String[]) β†’ String[]

Examples

Example 1

commands = ["1 INIT m1 0 5", "2 CREATE p1 m1 100", "3 CREATE p2 m1 50", "4 ATTEMPT p1", "5 ATTEMPT p2", "8 SUCCEED p1", "10 SUCCEED p2", "11 REFUND p1", "16 REFUND p2"]return = ["m1 50"]

In the above example, the reund of Payment Intent p1 succeeded because p1 was succeeded at time 8 and refunded at time 11, which is within merchant m1's refund timeout limit of 5. However, the refund of Payment Intent p2 failed because p2 was succeeded at time 10 and refunded at time 16, and 16 - 10 = 6 > 5, meaning it occured after m1's timeout limit. Because p1 was successfully refunded and p2 was not, the final balance of merchant m1 should be 50 :P

Constraints

  • For this exercise, assume 0–1,000 syntactically valid commands with the documented operation forms.
  • For this exercise, assume at most 500 distinct initialized merchants; the same bound applies to every ungraded helper mode.
  • IDs use 1–50 ASCII letters, digits, or underscores. Each command uses single ASCII spaces.
  • Numeric tokens use canonical decimal notation: 0 or nonzero-leading decimal digits, with a minus sign only for negative numbers; no leading zeros, plus signs, or -0.
  • Timed command timestamps strictly increase and are between 0 and 1,000,000,000.
  • Starting balances, amount arguments, and timeout limits are between -1,000,000,000 and 1,000,000,000. Negative CREATE/UPDATE amounts are ignored.
  • Use signed 64-bit arithmetic for aggregate merchant balances.

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

  • Corporate Card Expense RulesRippling Β· OA Β· PHONE SCREEN Β· ONSITE INTERVIEWRippling interview questions
  • Least Recently Used CacheMicrosoft Β· OA Β· PHONE SCREEN Β· ONSITE INTERVIEWMicrosoft interview questions
  • Parcel Event TrackingAirbnb Β· OAAirbnb interview questions
  • Process Banking OperationsVercel Β· OA
  • Expiring Authentication Token ManagerIBM Β· OAIBM interview questions
  • Layer History with Batch Undo and RedoFigma Β· OA Β· PHONE SCREENFigma interview questions
  • Event Statistics AggregatorWells Fargo Β· OAWells Fargo interview questions
  • Temporal Key-Field Database with Prefix ScansThe Trade Desk Β· OA
  • Per-Client Sliding-Window Rate LimiterGeneral Motors Β· OA
  • Stock Marking Position MonitorAkuna Capital Β· OAAkuna Capital interview questions

Interview reports that mention this question

  • Stripe SWE Intern Payment Intent OA: 1 Experience

Stripe interview experiences

  • Stripe SWE Onsite over Two Days: 1 Experience
  • Stripe New Grad SWE Phone Screen and Onsite: 2 Experiences
  • Stripe AI Coding Interview, Experienced SWE: 6 Experiences
  • Stripe SWE Intern Payout Scheduler Phone Screen: 1 Experience
  • Stripe New Grad SWE Onsite and HM Round: 1 Experience
All Stripe interview questionsSee Stripe hiring insights
Saved
class Solution {
    public String[] forAllIntentsAndPurposes4(String[] commands) {
      // write your code here
    }

}
Checking account…