📣 黑五网一特惠|VIP一年通行证5折,蓝莓、Offer多多同步特惠
回复: 0
跳转到指定楼层
上一主题 下一主题
收起左侧

Stripe 2026 Sumemr SWE HackerRank OA

🔗
匿名用户-BA0F9  23 分钟前 |倒序浏览

2026(4-6月) 码农类General 本科 实习@stripe - 网上海投 - 技术电面  | 😃 Positive 😐 Average | Other | 应届毕业生

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
Split Tender
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.

Function Description
Complete the function
  1. process_events
复制代码
in the editor below.
Function Parameters
  1. string events[n]
复制代码
: lines for each event in chronological order. Lines have a format defined by one of three schemas:
    1. timestamp,ADD_GIFTCARD,customer_id,card_id,amount,valid_before
    复制代码
    1. timestamp,CHARGE,charge_id,customer_id,amount,zip_code
    复制代码
    1. timestamp,REFUND,charge_id,refund_amount
    复制代码
    1. string surcharge_rates[m]
    复制代码
    : a list of non-overlapping zip code ranges mapped to a surcharge percentage in the format
    1. start_zip-end_zip:rate
    复制代码
    , where start and end are inclusive. Example:
    1. 90000-99999:0.05
    复制代码
    (representing $5%$).
General Constraints and Assumptions
  • Events are in chronological order by timestamp.
  • All event lines are well-formed.
    1. charge_id
    复制代码
    values are unique across
    1. CHARGE
    复制代码
    events.
    1. REFUND
    复制代码
    events always reference a prior
    1. CHARGE
    复制代码
    event.
  • Each
    1. charge_id
    复制代码
    will receive at most one
    1. REFUND
    复制代码
    event.
    1. card_id
    复制代码
    values from
    1. ADD_GIFTCARD
    复制代码
    events are unique.
    1. surcharge_rates
    复制代码
    contains non-overlapping, valid zip code ranges.
    1. 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
    1. 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
  1. string[n]
复制代码
: an array of strings, one per input event, in the same order.
  • For
    1. CHARGE
    复制代码
    events, return the formatted charge string using the schema
    1. CC_CHARGE_AMOUNT,GIFT_CARD_ID_1:AMOUNT_USED,GIFT_CARD_ID_2:AMOUNT_USED
    复制代码
    .
  • For all other event types, return an empty string
    1. ""
    复制代码
    unless a later part specifies otherwise.
  • 您好!
    本帖隐藏的内容需要积分高于 188 才可浏览
    您当前积分为 0。
    使用VIP即刻解锁阅读权限或查看其他获取积分的方式
    游客,您好!
    本帖隐藏的内容需要积分高于 188 才可浏览
    您当前积分为 0。
    VIP即刻解锁阅读权限 或 查看其他获取积分的方式
    Unlock interview details and practice with AI
    Popular Interview Questions from Top Companies
    rs, route the money back to the customer in the following priority:
    • Real dollars: Refund back to the credit card first, up to the amount that was actually charged to the credit card for the referenced
      1. charge_id
      复制代码
      , including surcharge.
    • Store credit second: If
      1. 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
      1. card_id
      复制代码
      must be formatted as
      1. REFUND_{charge_id}
      复制代码
      . This gift card has no expiration date.
    With $R$ the refund amount and $C$ the credit card amount originally charged (including surcharge): $$\text{CC_REFUND} = \min(R, C), \qquad \text{GC_REFUND} = R - \min(R, C)$$
    Refund-created gift cards participate in future
    1. 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:
    1. CC_REFUND,GC_REFUND
    复制代码
    Example Input:
    1. events = [
    2.   "1,ADD_GIFTCARD,cust1,gc1,5000,10",
    3.   "2,CHARGE,chg1,cust1,15000,90210",
    4.   "3,REFUND,chg1,12000"
    5. ]
    6. surcharge_rates = [
    7.   "90000-99999:0.05"
    8. ]
    复制代码
    Example Output:
    1. [
    2.   "",
    3.   "10500,gc1:5000",
    4.   "10500,1500"  # CC_REFUND, GC_REFUND
    5. ]
    复制代码
    Worked: $\min(12000, 10500) = 10500$ back to the credit card, and $12000 - 10500 = 1500$ as store credit on a new card
    1. REFUND_chg1
    复制代码
    .

上一篇:Grab 新加坡 Senior Full Stack HR面经(卡在薪资预算)
下一篇:Shopify University Recruiting SWE OA
您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表