FastPrepSplit Tender Part 4 - Refunds
Problems/Split Tender Part 4 - Refunds

Split Tender Part 4 - Refunds

Stripe logoStripe● HardFULLTIMEINTERNNEW GRADOAPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Stripe phone screen. This is Part 4, and it is about 99% the same as the reported question. The output rule for Part 2 was cropped, so we finish it with card IDs in alphabetical order. We chose the input size limits, the order for equal timestamps and the limits on identifiers.

Special thanks: 🌷 A special thank you to our lovely, amazing frenz who shared that this question appeared again on October 14, 2026, October 29, 2026, and November 6, 2026! ( ˘͈ ᵕ ˘͈♡) 💜

Many of Stripe's merchants rely on Stripe Terminal to accept in-person payments at the point of sale. In physical retail, it's common for a customer to cover a purchase with multiple payment methods. For example, they might cover a $100 purchase with a $40 gift card combined with a $60 credit card. This is called a split-tender transaction, and supporting it is a key requirement for retail merchants on Terminal.

For this multi-part question, we will be writing a system to process split-tender payments. When a transaction occurs, the system first deducts from the customer's available gift card balance, then charges the remaining balance to the customer's credit card. Given a chronological stream of payment events, your task is to calculate the correct credit card charge for each transaction. The question is broken down into four parts, each introducing a new event type: gift card expiration, regional credit card surcharges, and complex refund logic.

This exercise: Implement Part 4. Include split tendering, expiration, regional surcharges and refunds.

Split Tender Series

These four exercises build on one another. Each page includes the rules needed to solve that part.

  1. Split Tender Part 1 - Basic Split Tendering
  2. Split Tender Part 2 - Expiration Dates
  3. Split Tender Part 3 - Surcharges
  4. Split Tender Part 4 - Refunds (this part)

The function parameters below are shared by all four parts. This part uses only the event types and parameters listed in its interface.

Shared Function Parameters

string events[n]: lines for each event in chronological order. Lines have a format defined by one of three schemas:

  • timestamp,ADD_GIFTCARD,customer_id,card_id,amount,valid_before
  • timestamp,CHARGE,charge_id,customer_id,amount,zip_code
  • timestamp,REFUND,charge_id,refund_amount

string surcharge_rates[m]: a list of non-overlapping zip code ranges mapped to a surcharge percentage in the format start_zip-end_zip:rate, where start and end are inclusive. Example: 90000-99999:0.05 (representing 5%).

General Constraints and Assumptions

  • Events are in chronological order by timestamp.
  • All event lines are well-formed.
  • charge_id values are unique across CHARGE events.
  • REFUND events always reference a prior CHARGE event.
  • Each charge_id will receive at most one REFUND event.
  • card_id values from ADD_GIFTCARD events are unique.
  • surcharge_rates contains non-overlapping, valid zip code ranges.
  • zip_code values are five-digit numeric strings.

Monetary Representation and Precision

  • All monetary amounts in the input and output are represented as non-negative integer numbers of cents.
  • For example, $40.00 is represented as 4000.
  • Surcharge rates are decimal fractions; for example, 0.05 represents 5%.
  • Each surcharge calculation results in a whole number. You don't need to round.

Returns: string[n]: an array of strings, one per input event, in the same order.

  • For CHARGE events, return the formatted charge string using the schema CC_CHARGE_AMOUNT,GIFT_CARD_ID_1:AMOUNT_USED,GIFT_CARD_ID_2:AMOUNT_USED.
  • For all other event types, return an empty string "" unless a later part specifies otherwise.
  • The length of the output array must exactly match the length of the input events array.

Part 1: Basic split tendering

For Part 1, process ADD_GIFTCARD and CHARGE events. All customer balances start at 0.

When an ADD_GIFTCARD event is received, add the specified amount to the designated customer's total gift card balance. Return an empty string "".

When a CHARGE event is received, attempt to cover the transaction cost using the customer's available gift card balance first.

  • If the gift card balance is greater than or equal to the charge amount, deduct the charge amount from their gift card balance. The credit card charge is 0.
  • If the charge amount exceeds the gift card balance, drain the entire gift card balance to 0. The remaining unpaid amount becomes the credit card charge.

Output Format for CHARGE: Return a string starting with the credit card charge, followed by a comma-separated list of the gift cards debited and their amounts (CARD_ID:AMOUNT). If no gift cards were debited, output only the credit card charge.

CC_CHARGE_AMOUNT,GIFT_CARD_ID_1:AMOUNT_USED,GIFT_CARD_ID_2:AMOUNT_USED

The single-active-card restriction applies only to Part 1. This exercise allows multiple gift cards, as described in Part 2.

Part 2: Expiration dates

All constraints from Part 1 still apply. In this part, each gift card has its own individual balance, and a customer may hold multiple gift cards simultaneously, tracked by card_id. Additionally, gift cards have expiration dates: they must be used before their valid_before time.

When a CHARGE event occurs at time T, evaluate the customer's available gift cards:

  • A gift card is valid only if T is strictly less than its valid_before value. If T is at or after valid_before, the gift card is expired and its balance permanently voided.
  • The system must charge valid gift cards by the earliest expiration date first. Completely drain one gift card before moving to the next.
  • Gift cards with no expiration date are considered valid forever and should be used after all valid gift cards with finite expiration timestamps.
  • If multiple gift cards share the exact same expiration timestamp, prioritize the card whose card_id appears first lexicographically.

Output Format for CHARGE: Identical to Part 1. Gift cards must be debited according to the priority rules above. Now that multiple gift cards can be consumed in a single charge, cards must be sorted.

Practice clarification for the cropped output rule: Sort positive debit entries lexicographically by card_id in the output, independently of their spending order.

Part 3: Surcharges

All constraints from previous parts still apply. Credit card transactions are now subject to regional processing fees using the zip_code and surcharge_rates.

When a CHARGE event occurs, first split the raw charge amount between gift cards and credit card exactly as before. However, our system must now apply a surcharge on the final CC_CHARGE amount according to the following rules:

  • Identify which range in surcharge_rates the event's zip code falls into. If it does not fall into any range, the rate is 0.
  • Calculate the surcharge strictly on the portion of the bill falling to the credit card. Gift card deductions are not subject to surcharges.
  • The surcharge is calculated as credit_card_portion × rate, then added to the original credit_card_portion to arrive at the final CC_CHARGE. For example, a $100 credit card portion at a 5% surcharge (0.05) yields a final CC_CHARGE of $105.00.

Output Format for CHARGE: Identical to Part 1 and Part 2, but the CC_CHARGE value must reflect the newly calculated total including the surcharge.

Part 4: Refunds

All constraints from previous parts still apply. You must now handle REFUND events targeting a historical charge_id.

A REFUND event has the following format:

timestamp,REFUND,charge_id,refund_amount

The refund_amount represents the total amount to return to the customer, including any refundable credit card surcharge. Refund amounts are guaranteed not to exceed the total amount originally paid for the referenced charge, including surcharge. Each charge_id will receive at most one REFUND event.

When a refund occurs, route the money back to the customer in the following priority:

  1. Real dollars: Refund back to the credit card first, up to the amount that was actually charged to the credit card for the referenced charge_id, including surcharge.
  2. Store credit second: If refund_amount exceeds the amount refundable to the credit card, refund the remaining amount as store credit by creating a new gift card for the original customer. The new card_id must be formatted as REFUND_{charge_id}. This gift card has no expiration date.

Refund-created gift cards participate in future CHARGE events like any other gift card. Refund-created gift cards never expire. When choosing gift cards for a future charge, non-expiring gift cards are used after all valid gift cards with finite expiration timestamps.

Output Format for REFUND: Return a flat string containing the amount refunded to the credit card and the amount refunded to the store credit gift card, separated by a single comma: CC_REFUND,GC_REFUND

Example Input

events = [
  "1,ADD_GIFTCARD,cust1,gc1,5000,10",
  "2,CHARGE,chg1,cust1,15000,90210",
  "3,REFUND,chg1,12000"
]

surcharge_rates = [
  "90000-99999:0.05"
]

Example Output

[
  "",
  "10500,gc1:5000",
  "10500,1500" # CC_REFUND, GC_REFUND
]

Details

Complete the function process_events in the editor below.

In this practice interface, the method is named processEvents. Supplied gift cards have finite expiration timestamps. Non-expiring cards are created by refunds in this part. User-supplied card IDs cannot begin with REFUND_.

Function

processEvents(events: String[], surchargeRates: String[]) → String[]

Examples

Example 1

events = ["1,ADD_GIFTCARD,cust1,gc1,5000,10","2,ADD_GIFTCARD,cust2,gc2,2000,15","3,CHARGE,chg1,cust2,3000,10000","4,CHARGE,chg2,cust1,3000,10000"]surchargeRates = []return = ["","","1000,gc2:2000","0,gc1:3000"]

The first purchase drains gc2 and charges 1000 cents to the credit card. The second consumes 3000 cents from gc1.

Example 2

events = ["1,ADD_GIFTCARD,cust1,gc1,5000,10","2,ADD_GIFTCARD,cust1,gc2,4000,5","3,CHARGE,chg1,cust1,6000,10000","11,CHARGE,chg2,cust1,1000,10000"]surchargeRates = []return = ["","","0,gc1:2000,gc2:4000","1000"]

gc2 expires first and is drained before gc1; output card IDs are sorted independently. At timestamp 11 the remaining gc1 balance is expired.

Example 3

events = ["1,ADD_GIFTCARD,cust1,gc1,5000,10","2,CHARGE,chg1,cust1,15000,90210"]surchargeRates = ["80000-89999:0.02","90000-99999:0.05"]return = ["","10500,gc1:5000"]

The gift card covers 5000 cents. The 10000 cent credit-card principal receives a 500 cent surcharge.

Example 4

events = ["1,ADD_GIFTCARD,cust1,gc1,5000,10","2,CHARGE,chg1,cust1,15000,90210","3,REFUND,chg1,12000"]surchargeRates = ["90000-99999:0.05"]return = ["","10500,gc1:5000","10500,1500"]

The refund first returns all 10500 cents actually charged to the credit card. The remaining 1500 cents create the never-expiring REFUND_chg1 card.

Constraints

  • For this exercise, assume there are between 1 and 10^5 events.
  • For this exercise, assume events with equal timestamps are processed in input order.
  • For this exercise, assume all input customer, card and charge IDs contain ASCII letters, digits or underscores, have length from 1 to 64, and contain no commas.
  • For this exercise, assume each input monetary amount is at most 10^9 cents, and all running balances and intermediate money arithmetic fit signed 64-bit integers.
  • For this exercise, assume supplied gift cards have finite expiration timestamps, and timestamps and finite expirations are integers from 0 to 10^9.
  • For this exercise, assume debited gift cards are listed lexicographically by card_id in the output, independently of their spending order.
  • For this exercise, assume there are at most 10^4 surcharge ranges.
  • For this exercise, assume rates are between 0 and 1 with at most six fractional digits.
  • For this exercise, assume user-supplied card IDs do not begin with REFUND_.
  • This part: Process ADD_GIFTCARD, CHARGE and REFUND events with the rules of all four parts.

More Stripe Phone Screen questions

  • Merchant Payout Reserve CalculatorPHONE SCREEN · Seen Nov 2026
  • Parse Boolean Rule ExpressionsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Linked Merchants Within Two HopsPHONE SCREEN · Seen Nov 2026
  • Merchant Matching, Parts 1–2: Shared Fields and Weighted ThresholdsPHONE SCREEN · Seen Nov 2026
  • Business Account KYC Verification — Parts 1–5PHONE SCREEN · Seen Nov 2026
  • Financial Account LedgerOA · PHONE SCREEN · Seen Nov 2026
  • Invoice / Payment ReconciliationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Merchant Payout Scheduler, Part 2: Per-Merchant SchedulesPHONE SCREEN · Seen Nov 2026
  • Transaction Fee Calculator — Parts 1–2: Basic Fee Calculation and Conditional Fee RulesPHONE SCREEN · Seen Nov 2026
  • Render a Task Tree from CSV RowsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Progressive Banking SystemAirbnb · OAAirbnb interview questions
  • 15-Minute Chat Session TrackerOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Named Async Task SchedulerAirwallex · OAAirwallex interview questions
  • Weighted LFU CacheIMC Trading · OAIMC Trading interview questions
  • Weighted LFU CacheMicrosoft · OAMicrosoft interview questions
  • Capacity-Limited Timed CacheNetflix · PHONE SCREENNetflix interview questions
  • Tiered Expiring Item StoreHudson River Trading · PHONE SCREEN · ONSITE INTERVIEWHudson River Trading interview questions
  • LRU Cache with Expiring EntriesPaytm · PHONE SCREENPaytm interview questions
  • Cloud Compute Credits SystemCoinbase · OACoinbase interview questions
  • Tiered Expiring Item StoreAkuna Capital · PHONE SCREENAkuna Capital interview questions

Interview reports that mention this question

  • Stripe OA: What It Tests (2026)

Stripe interview experiences

  • Stripe New Grad SWE OA and Phone Screen: 2 Experiences
  • Stripe Experienced SWE OA and Onsite Questions: 3 Experiences
  • Stripe SWE Intern Linked Merchants Team Screen: 1 Experience
  • Stripe SWE Onsite over Two Days: 1 Experience
  • Stripe New Grad SWE Phone Screen and Onsite: 2 Experiences
All Stripe interview questionsSee Stripe hiring insights
Saved
class Solution {
    public String[] processEvents(String[] events, String[] surchargeRates) {
        // write your code here
    }
}
Checking account…