Merchant onboarding CSV validator
I was asked this
No reports yet. Sign in to say where you were asked it.
Merchants submit their business details as rows of a simple CSV. Before a merchant can accept payments, every row must pass a set of checks. Write validate_records(data, forbidden_words, ignore_words) -> list[str].
Input
-
data: a list of strings.data[0]is a header with six comma-separated column names:business_name,legal_name,statement_descriptor,short_descriptor,url,product_description. The columns can appear in any order. Each later string is one merchant. You can assume fields contain no commas or quotes. -
forbidden_words: words or multi-word phrases that may not appear in customer-facing fields. -
ignore_words: filler words (for examplethe,inc,llc) that are skipped when comparing the name with the descriptor.
Output
One string per data row, in order: "VERIFIED", or "NOT VERIFIED: <reason>" for the first rule that fails.
Rules (checked in this order; trim fields, compare case-insensitively, and treat any non-alphanumeric character as a word separator)
- Every column is non-blank. Reason:
missing <column>. A row with the wrong number of cells getsmalformed row. -
statement_descriptoris 5–22 characters long, andshort_descriptoris 2–10. Reason:<column> length. - No forbidden word or phrase appears, as whole words, in
business_name,statement_descriptororshort_descriptor. Reason:forbidden word in <column>. - Remove ignore words from
business_nameand fromstatement_descriptor. At least half of the name's remaining distinct words must appear in the descriptor. If no words remain in the name, the rule fails. Reason:descriptor does not match business_name.
Example 1
forbidden_words = ["online store"]
ignore_words = ["llc", "co"]
data = [
"business_name,legal_name,statement_descriptor,short_descriptor,url,product_description",
"Juniper Bakery,Juniper Bakery LLC,JUNIPER BAKERY,JUNIPER,juniper.example,Bread",
"Best Online Store,Best LLC,BEST ONLINE STORE,BEST,best.example,Gadgets",
"Juniper Bakery,Juniper Bakery LLC,JB,JUNIPER,juniper.example,Bread",
]
Output: ["VERIFIED", "NOT VERIFIED: forbidden word in business_name", "NOT VERIFIED: statement_descriptor length"].
Example 2
Northwind Trading Co with descriptor NORTHWIND PAYMENTS is verified: co is ignored, and 1 of the 2 remaining words matches, which is exactly half. Blue Harbor Fish Market with descriptor HARBOR GOODS fails rule 4, because only 1 of 4 words matches.
Expect follow-ups such as reporting every failed rule, handling quoted CSV fields, and making the rules configurable.
Reconstructed from the reported question; details may differ from what interviewers ask.
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. Free with an account: one full answer per company.
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. Free with an account: one full answer per company.
