KatInterview

Tiered Identity Validation for Business Onboarding

StringsAuto-graded · 20 test cases
MediumAuto-gradedStringsstringshashingsimulation

Last updated

Tests your ability to implement a sequential rule-engine with string normalization, token-set comparison, and strict short-circuit logic across three validation tiers.

Problem

A financial platform needs to validate businesses before granting them access to payment features. Validation works in three progressive tiers. A business must clear each tier before the next one is evaluated. Your job is to determine the highest tier a submission reaches.

Implement check_business_identity(submitted: dict, registry: dict) -> int, which returns 0, 1, 2, or 3 — the highest tier passed.


Tier 1 — Format Check

Return 1 if all three conditions below hold; otherwise return 0.

  1. submitted["legal_name"] must be a string with at least one non-whitespace character.
  2. submitted["country"] must be a string of exactly two ASCII letters (case-insensitive).
  3. submitted["tax_id"] must be a string that, after stripping all hyphens (-) and spaces, contains only alphanumeric characters and has a length between 8 and 10 inclusive.

Tier 2 — Registry Match

Requires Tier 1. Return 2 if all three conditions below hold; otherwise return 1.

  1. submitted["country"] matches registry["country"] case-insensitively.
  2. submitted["tax_id"] matches registry["tax_id"] after stripping hyphens and spaces from both sides and uppercasing.
  3. The business name tokens of submitted["legal_name"] and registry["legal_name"] are identical, where business name tokens are computed as follows:
    • Lowercase the string.
    • Remove every character that is not an ASCII letter, digit, or whitespace.
    • Split on whitespace into tokens.
    • Discard any token that belongs to the set {"inc", "llc", "corp", "corporation", "ltd", "co", "company"}.
    • Both sides must produce at least one token, and those token sets must be equal.

Tier 3 — Ownership Match

Requires Tier 2. Return 3 if both conditions below hold; otherwise return 2.

  1. submitted.get("owners", []) is a non-empty list.
  2. Every name in submitted["owners"] has a match somewhere in registry.get("owners", []). Two names match when, after lowercasing and removing every character that is not alphanumeric or whitespace, their sets of whitespace-delimited tokens are identical (so "Jane Doe" and "Doe, Jane" match).

Constraints

  • Both submitted and registry are plain dicts; any key may be absent or hold an unexpected type — handle gracefully without raising.
  • Country codes contain only printable characters; no guarantee they are valid ISO codes.
  • Tax ID strings may contain hyphens, spaces, letters, and digits; other characters are possible.
  • Owner lists, when present, contain strings; the registry may have more owners than the submission.
  • Name comparison uses sets of tokens, so word order is irrelevant.
  • A legal name whose tokens are entirely suffixes (e.g., "Inc. LLC") must fail Tier 2.
  • 1 ≤ len(submitted["legal_name"]) ≤ 200 when the key is present and a string.
  • 1 ≤ len(owners) ≤ 50 per side when the key is present and a list.

Examples

Example 1

Input: check_business_identity({'legal_name': 'Acme Payments, Inc.', 'country': 'us', 'tax_id': '12-345678', 'owners': ['Jane Doe', 'Bob Smith']}, {'legal_name': 'ACME PAYMENTS LLC', 'country': 'US', 'tax_id': '12345678', 'owners': ['Doe, Jane', 'Smith Bob', 'Alice Brown']})

Output: 3

Example 2

Input: check_business_identity({'legal_name': 'Global Freight Ltd', 'country': 'CA', 'tax_id': 'AB-998877', 'owners': []}, {'legal_name': 'Global Freight Company', 'country': 'CA', 'tax_id': 'AB998877', 'owners': ['Carol Danvers']})

Output: 2

Hints

Hint 1

Break the problem into three small, independently testable helpers — one per tier — and short-circuit: if tier N fails, return N-1 immediately without evaluating later tiers.

Hint 2

For legal name comparison, the tricky edge case is a name that consists entirely of legal suffixes like 'Inc.' or 'Co.' — after stripping suffixes the token set is empty, and an empty set should never match anything.

Hint 3

Normalise the tax ID (strip hyphens and spaces, then uppercase) on both the submitted and registry sides before comparing, so differences in formatting don't cause false negatives.