OA: IT ASKED ABOUT A LOAD BALANCER QUESTION SIMILAR TO https://www.codinzhub.com/question/notebook-platform-stripe-online-assessment-off-campus
TECHNICAL SCREENING ROUND: HERE THEY HAVE ASKED A MULTIPART QUESTIONS BASED ON Transaction Fee Calculator
OF COURSE THE VALUES ARE DIFFERENT BUT THE MAIN QUESTIONS IS SAME
You are given a CSV string representing payment transactions. Write a function that parses the CSV and returns a CSV string containing the total processing fee for each merchant.
Each transaction contains the following fields:
| Column | Description |
|---|---|
transaction_id | Unique transaction identifier |
merchant_id | Merchant associated with the transaction |
status | Transaction status |
payment_provider | Payment provider, such as card, bank_transfer, or |
Last updated Oct 24, 2026
paypalbuyer_country | Buyer's country code, such as US, DE, or FR |
currency | Transaction currency, such as USD or EUR |
amount | Non-negative transaction amount in the specified currency |
The CSV may contain extra whitespace, which should be handled appropriately.
def compute_fees_per_merchant(
csv_str,
base_rate_by_provider,
completed_rate_by_provider_and_country,
fx_to_usd
) -> str:
pass
csv_str: CSV string containing transaction records.base_rate_by_provider: Mapping of payment providers to their standard processing rates.completed_rate_by_provider_and_country: Mapping of (payment_provider, buyer_country) pairs to completed-payment rates.fx_to_usd: Mapping of currency codes to USD conversion rates.The following statuses may appear:
payment_completedpayment_pendingpayment_failedrefund_completeddispute_wondispute_lostFor refund_completed, the processing fee is zero.
fee_usd = 0
For payment_completed, first convert the transaction amount to USD.
amount_usd = amount * fx_to_usd[currency]
Look up the completed-payment rate using the payment provider and buyer country.
fee_usd = amount_usd * completed_rate + 0.30
If the provider-country combination is missing, use the provider's base rate instead.
For payment_pending, payment_failed, dispute_won, and dispute_lost, use the provider's base rate.
amount_usd = amount * fx_to_usd[currency]
fee_usd = amount_usd * base_rate + 0.30
0.$0.30 fee when the provider is unknown.1.0.Return a CSV string with the following header:
merchant_id,total_fee_usd
merchant_id in ascending order.Discuss the time complexity and explain how you would test edge cases, including:
Given a CSV string containing payment transactions, calculate the total processing fee for each user.
Return a dictionary mapping each user to their total fee in integer USD cents.
Implement the function:
def solution(csv_string):
pass
When the input is non-empty, the CSV contains this exact header:
user,status,payment_provider,amount
Each subsequent row contains:
| Column | Description |
|---|---|
user | User associated with the transaction |
status | Transaction status |
payment_provider | Payment provider |
amount | Transaction amount in USD |
The amount is non-negative and has at most two decimal places.
| Provider | Processing Rate |
|---|---|
card | 2.9% |
bank_transfer | 1.0% |
wallet | 1.5% |
For the following statuses:
payment_completedpayment_failedpayment_pendingCalculate the fee as:
fee = amount * provider_rate + 0.30
For dispute_lost, charge a flat fee of $15.00.
fee = 15.00
For refund_completed and dispute_won, the fee is zero.
fee = 0.00
For example:
100.00 * 0.029 + 0.30 = 3.20 USD
3.20 USD = 320 cents
Return a dictionary mapping each user to their total fees in cents.
Every user appearing in the CSV must be included, even if their total fee is zero.
Ignore blank lines and rows with an empty user field. If the input is empty or contains only whitespace, return an empty dictionary.
csv_string = """user,status,payment_provider,amount
alice,payment_completed,card,100.00
bob,payment_failed,bank_transfer,50.00
alice,refund_completed,card,20.00
bob,dispute_lost,wallet,80.00"""
{
"alice": 320,
"bob": 1580
}
100.00 * 0.029 + 0.30 = 3.20 USD, or 320 cents.50.00 * 0.01 + 0.30 = 0.80 USD, or 80 cents.1500 cents.Therefore, Alice owes 320 cents and Bob owes 1580 cents.
csv_string = """user,status,payment_provider,amount
alice,payment_pending,wallet,10.00
alice,payment_completed,wallet,0.99
carol,dispute_won,card,42.00"""
{
"alice": 76,
"carol": 0
}
10.00 * 0.015 + 0.30 = 0.45 USD, or 45 cents.0.99 * 0.015 + 0.30 = 0.31485 USD, rounded half-up to $0.31, or 31 cents.45 + 31 = 76 cents.user,status,payment_provider,amount when non-empty.card, bank_transfer, or wallet.payment_completed, payment_failed, payment_pending, refund_completed, dispute_lost, or dispute_won.csv.DictReader.Decimal and ROUND_HALF_UP to avoid floating-point rounding errors.Given a CSV string of payment transactions and a currency-to-USD exchange-rate dictionary, calculate the total transaction-processing fee for each user in integer USD cents.
Unlike Part 2, the transaction amount may be in a currency other than USD. Additionally, completed-payment rates depend on both the payment provider and the buyer's country.
Implement the function:
def solution(csv_string, exchange_rates):
pass
When the input is non-empty, the CSV contains this exact header:
user,status,payment_provider,buyer_country,currency,amount
| Column | Description |
|---|---|
user | User associated with the transaction |
status | Transaction status |
payment_provider | card, bank_transfer, or wallet |
buyer_country | Buyer's country code |
currency | Currency code of the transaction |
amount | Non-negative transaction amount |
The exchange_rates dictionary maps each currency to the USD value of one unit of that currency.
For example:
exchange_rates = {
"USD": 1.0,
"EUR": 1.10,
"GBP": 1.25
}
Convert each transaction amount using the exchange-rate dictionary.
converted_usd = amount * exchange_rates[currency]
For payment_completed, the processing rate depends on both the provider and the buyer's country.
| Provider | US / CA | GB | DE / FR / AT | All Other Countries |
|---|---|---|---|---|
card | 2.9% | 2.5% | 2.3% | 3.1% |
bank_transfer | 1.2% | 1.1% | 1.0% | 1.4% |
wallet | 1.8% | 1.8% | 1.8% | 1.8% |
Calculate the fee as:
fee = converted_usd * country_specific_rate + 0.30
The wallet rate is always 1.8%, regardless of the country.