Software Engineer • Senior-Level
Software Engineer • Senior-Level
High QualityPrep Other Coding Questions Asked by Stripe
Continue with targeted prep from Stripe's coding question bank.
Interview Summary
The task involved processing chat session records, calculating token-based charges under a pay-as-you-go pricing model, and aggregating each user's total monthly spending.
Interview Details
OA: AI Token Billing Calculation
I was asked to implement a billing component for a chat-based AI platform that charges users based on their input and output token usage. The system receives a list of chat session records for a single month, and each record contains a user identifier, input token count, output token count, and subscription plan. A user can have multiple chat sessions during the month. The goal is to calculate the total charges for each user across all their sessions and return the results in a specified format.
Part 1 — Parse Chat Session Records
The input is an array of strings called sessions. Each string represents one chat session and contains exactly four comma-separated fields:
"<user_id>,<input_tokens>,<output_tokens>,<plan>"
The fields represent:
user_id: The identifier of the user who initiated the session.input_tokens: The number of input tokens consumed.output_tokens: The number of output tokens generated.plan: The user's billing plan.
For this problem, every session uses the payg (pay-as-you-go) plan. Multiple session records may belong to the same user, and every record must be included when calculating monthly charges.
Part 2 — Calculate Per-Session Token Charges
The platform uses different pricing rates for input and output tokens:
| Token Type | Price per 100 Tokens |
|---|---|
| Input tokens | $0.03 |
| Output tokens | $0.04 |
Charges are calculated using complete blocks of 100 tokens per session. Any remaining tokens that do not form a complete block are not
Unlock Full Details
Create a free account to unlock this interview experience report.