Coding questions · Stripe
Verify Business Records with Field and Name Rules
Validate business records for required values, field length, prohibited description text, and name-to-nickname overlap while preserving input order.
Implement verifyBusinesses(records, requiredFields, lengthField, forbiddenPhrases, ignoredSuffixes). Apply the validation stages below and return one status line for each record that has a business name, preserving input order.
Inputs and Output
recordsis a list of string-to-string maps. The designated fields arebusiness_name,description, andnickname; other fields, such asurl, may also be present.requiredFieldslists the fields that must have values. It includesdescriptionandnickname, and excludesbusiness_name, which has its own skip rule.lengthFieldnames the field whose original value must contain between 5 and 32 characters, inclusive. It is eitherbusiness_nameor one ofrequiredFields.forbiddenPhrasescontains prohibited description substrings, including any prohibited single words or multiword phrases.ignoredSuffixescontains normalized legal suffix words, such asllcorinc, to ignore at the end of a business name.
Return strings of the form "verified <business_name>" or "not verified <business_name>", replacing the placeholder with the record's original business-name value.
Validation Rules
- A missing field is treated as an empty string. A value is blank if it is empty or contains only ASCII spaces. Skip records with a blank
business_name; they produce no output. - Every field in
requiredFieldsmust be nonblank. - Count every character in the original
lengthFieldvalue, including spaces. Its length must be from 5 through 32. - The original
descriptionmust not contain any string inforbiddenPhrases. This practice version uses case-sensitive literal substring matching, including spaces inside a phrase; it does not require word boundaries. - For the name-overlap check, split
business_nameandnicknameinto maximal runs of ASCII letters and digits, and lowercase those tokens. Repeatedly remove trailing business-name tokens listed inignoredSuffixes. Do not remove suffix words from the middle of the name. - At least half of the remaining business-name token occurrences must appear as whole tokens in
nickname. Each business-name occurrence counts separately, even if repeated; a matching nickname token can satisfy each occurrence of that word. A name with no remaining tokens fails this check.
A record is verified only if it passes all checks after the skip rule. No additional URL, legal-identity, or business-validity check is part of this exercise.
Constraints
- There are at most 2,000 records, with at most 20 fields each. Values contain only printable ASCII characters and are at most 200 characters long.
- Field names are nonempty and case-sensitive.
requiredFieldscontains no duplicates. - There are at most 50 nonempty forbidden phrases, each at most 50 characters long. An empty phrase list imposes no description restriction.
- There are at most 50 ignored suffixes. Each is a nonempty lowercase ASCII letter-or-digit token. An empty suffix list removes nothing.
- An empty record list returns an empty list.
Example 1
records = [
{"business_name": " ", "url": "", "nickname": "", "description": ""},
{"business_name": "Acme Labs LLC", "url": "acme.test", "nickname": "Acme Labs", "description": "Software tools"},
{"business_name": "North Star Inc.", "url": "north.test", "nickname": "North", "description": "Payment tools"}
]
requiredFields = ["url", "nickname", "description"]
lengthField = "nickname"
forbiddenPhrases = ["loan", "cash advance"]
ignoredSuffixes = ["llc", "inc"]
Output: ["verified Acme Labs LLC", "verified North Star Inc."]
The blank-name record is skipped. After removing inc, one of the two name tokens in the last record appears in its nickname, meeting the half-overlap requirement exactly.
Example 2
records = [
{"business_name": "Bright Oak LLC", "url": "bright.test", "nickname": "Bright", "description": "loan services"},
{"business_name": "Red Pine LLC", "url": "red.test", "nickname": "Green", "description": "Garden tools"},
{"business_name": "Blue Sky LLC", "url": "", "nickname": "Blue Sky", "description": "Travel tools"},
{"business_name": "Tiny Studio", "url": "tiny.test", "nickname": "Tiny", "description": "Design tools"}
]
requiredFields = ["url", "nickname", "description"]
lengthField = "nickname"
forbiddenPhrases = ["loan", "cash advance"]
ignoredSuffixes = ["llc", "inc"]
Output: ["not verified Bright Oak LLC", "not verified Red Pine LLC", "not verified Blue Sky LLC", "not verified Tiny Studio"]
The records fail because of a forbidden description substring, insufficient name overlap, a blank required field, and a nickname shorter than five characters, respectively.
Verify Business Records with Field and Name Rules
Approach
Process records in their original order. Read missing fields as empty strings and skip a record immediately when its business name is empty or contains only ASCII spaces. For every other record, test all configured required fields for nonblank values, check the original chosen length-field value against the inclusive 5-to-32 range, and reject any literal case-sensitive forbidden substring in the original description.
For a record still eligible, tokenize its business name and nickname into maximal ASCII alphanumeric runs and lowercase those runs. Store the ignored suffixes as a membership set and repeatedly remove only matching tokens from the end of the business-name list. Build a set of nickname tokens. Count business-name token occurrences whose value belongs to that set, without deduplicating the business-name list. Require a nonempty remaining list and twice the matching count to be at least its size.
Each early check is exactly one required predicate. The tokenizer forms precisely the runs stated in the contract; repeated removal stops at the first trailing token not in the suffix set, leaving middle occurrences untouched. Membership in the nickname set asks whether a whole token appears at least once, while iterating the business list preserves repeated occurrences. The integer inequality expresses the half-overlap threshold without rounding errors. Thus the status is verified exactly when every required check passes. Prefixing the untouched original name and appending only non-skipped records preserves spelling, punctuation, spacing and order.
Let N be the record count, F the required-field count, P the forbidden-phrase count, L <= 200 the maximum record-value length, and W <= 50 the maximum phrase length. A direct implementation takes O(N*(FL + PL*W + L)) string work in a conservative substring-search bound, plus field-name lookup/hashing/comparison costs. C++ map lookup additionally costs O(log D) comparisons for D <= 20 fields, and copies selected field values. Suffix and nickname hash lookups are expected constant-time aside from their string processing. Working storage is O(L + S) for tokens and suffix strings, where S is the total supplied suffix text; returned status strings occupy their required output space. The inputs are not mutated.
- Time complexity: O(N*(FL + PL*W + L)) conservative string work, plus field-name/map lookup costs and suffix-set construction; record values have L <= 200 and phrases have W <= 50.
- Space complexity: O(L + S) auxiliary token/suffix storage, plus returned status strings; S is total ignored-suffix text.