FastPrepMerchant Payout Scheduler, Part 1

Merchant Payout Scheduler, Part 1

Stripe logoStripe● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

A merchant's transaction earnings accumulate until the next scheduled payout. Given the transactions and a configurable payoutInterval, compute all payouts.

Each element of transactions has the format id,amount,day. The amount is an integer number of cents, and the day is an integer. Transactions may arrive in any order.

Payout schedule

Payouts occur on days payoutInterval, 2 * payoutInterval, and so on. A transaction belongs to the first payout day strictly greater than its transaction day:

payoutDay = (day / payoutInterval + 1) * payoutInterval

Here division is integer division. A transaction exactly on a scheduled payout day belongs to the following payout. For example, when payoutInterval = 7, days 0 through 6 pay out on day 7, and a transaction on day 7 pays out on day 14. This matches the reported example.

The interval is an argument and may differ between calls. Do not hardcode 7.

Payout lines

Return one string for each payout containing at least one transaction, ordered by increasing payout day. Sum the included amounts using integer-cent arithmetic, then format the total in dollars with exactly two digits after the decimal point:

Day 7: $1000.49 [txn_1, txn_2, txn_3]

For this exercise, preserve the original input order of transaction IDs within each payout. Separate IDs with a comma and one space. Do not emit empty payout periods. A payout containing zero-cent transactions still appears; empty input returns an empty array.

The screenshot shows a getPayouts placeholder and transaction setup in the caller. The signature here exposes the transactions and interval directly and returns the printed lines for practice.

Function

getPayouts(transactions: String[], payoutInterval: int) → String[]

Examples

Example 1

transactions = ["txn_1,10050,1","txn_2,39999,2","txn_3,50000,4","txn_4,29995,7","txn_5,24999,9","txn_6,8050,15","txn_7,15001,29"]payoutInterval = 7return = ["Day 7: $1000.49 [txn_1, txn_2, txn_3]","Day 14: $549.94 [txn_4, txn_5]","Day 21: $80.50 [txn_6]","Day 35: $150.01 [txn_7]"]

The first three transactions total 100049 cents. Transaction txn_4 occurs on day 7, so it joins txn_5 in the day-14 payout. Day 28 has no transactions to pay and is omitted. This preserves the reported example's values and results.

Example 2

transactions = ["later,1,4","first,199,0","edge,200,2","same,5,0"]payoutInterval = 2return = ["Day 2: $2.04 [first, same]","Day 4: $2.00 [edge]","Day 6: $0.01 [later]"]

This practice example changes the interval to 2 and supplies unordered days. Exact-boundary days 2 and 4 move to the following payout, while IDs within the day-2 payout retain their input order.

Constraints

  • 0 <= transactions.length <= 100000.
  • 1 <= payoutInterval <= 10^9.
  • Every transaction has exactly three comma-separated fields: id,amount,day.
  • IDs are unique and contain 1 to 64 ASCII letters, digits, or underscores.
  • 0 <= amount <= 10^9 cents and 0 <= day <= 10^9.
  • Use 64-bit integers for accumulated amounts and intermediate arithmetic.

Source note: Reflection-cleaned reconstruction of the uploaded question image. Wording and example values were checked against the original; layout and typography have been reformatted.

More Stripe problems

See Stripe hiring insights
public String[] getPayouts(String[] transactions, int payoutInterval) {
    // Write your code here.
}
transactions["txn_1,10050,1","txn_2,39999,2","txn_3,50000,4","txn_4,29995,7","txn_5,24999,9","txn_6,8050,15","txn_7,15001,29"]
payoutInterval7
expected["Day 7: $1000.49 [txn_1, txn_2, txn_3]", "Day 14: $549.94 [txn_4, txn_5]", "Day 21: $80.50 [txn_6]", "Day 35: $150.01 [txn_7]"]
Checking account…