← Questions
Import card data from another processor
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Stripe's technical phone screen, last asked Dec 2023. It tests csv, parsing and hash map.
A merchant is moving its customers' saved cards from another payment processor. You get two CSV strings: the cards export and a file that maps customers to email addresses. Produce the import rows: one per card, with the customer's email, the cardholder's full name, the card number, and the expiry split into a month and a four-digit year.
Interface
Unless you agree on a different interface with the interviewer, assume:
-
import_cards(cards_csv: str, users_csv: str) -> list[str]-
cards_csvhas the headercustomer_id,card_id,first_name,last_name,card_number,expiration. The expiration isMYYorMMYY, with a year in the 2000s. -
users_csvhas the headercustomer_id,email, in any order. - Output: the header
customer_id,card_id,email,cardholder_name,card_number,exp_month,exp_year, then one row per card in input order. - The cardholder name joins the non-empty name parts with one space. The month has no leading zero; the year has four digits.
-
Example
cards_csv:
customer_id,card_id,first_name,last_name,card_number,expiration
cus_100,card_100,John,Doe,4242424242424242,1023
cus_200,card_200,Jane,Doe,5555555555554444,921
cus_300,card_300,,Roberts,6011111111111117,820
users_csv:
customer_id,email
cus_300,rob@example.com
cus_100,john@example.com
cus_200,jane@example.com
-> customer_id,card_id,email,cardholder_name,card_number,exp_month,exp_year
cus_100,card_100,john@example.com,John Doe,4242424242424242,10,2023
cus_200,card_200,jane@example.com,Jane Doe,5555555555554444,9,2021
cus_300,card_300,rob@example.com,Roberts,6011111111111117,8,2020
Constraints
- Up to 100,000 rows in each file. Fields have no commas, line breaks or surrounding spaces.
- IDs are unique, every card's customer has exactly one email, and at least one name part is present.
- Every expiration is 3 or 4 characters with a month from 1 to 12.
Clarifying questions
- How is a three-digit expiration read:
125as January 2025, never December 2005? - What if a customer has no email row: skip the card, leave the email empty, or fail?
- Should card numbers be validated (length, Luhn check) or masked in logs?
- Are there CSV quoting rules to handle?
What a strong answer covers
- A dict from customer ID to email, built first, so each card is O(1).
- Expiry parsing by length: the last two characters are the year, the rest is the month.
- Name joining that skips empty parts, so there is no stray space.
- Using the
csvmodule rather than manual splitting, and keeping input order. - Handling sensitive data: never print full card numbers.
- Tests: three- and four-character expiries, a missing first or last name, an empty file.
Follow-ups
- Validate card numbers with the Luhn check and report bad rows.
- Drop cards that have already expired relative to a given date.
- The files are too large for memory. Join them as streams.
Where it's asked
- Stripe · Technical phone screen · Last asked Dec 202360 min · One realistic task in parts, in a project editor (CoderPad project mode or HackerRank Projects) with several files and tests
What it tests
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
