Vendor Service String Verification
viaLeetCode
Problem Vendors submit hotel-service strings ("tree wifi") that must be verified against a catalog of known terms ("free wifi"): if the input differs from a known term by at most one character, auto-correct it to that term; otherwise reject with an exception back to the vendor.
Input / Output
- Input: vendor string, set of valid service terms.
- Output: the corrected/validated term, or a thrown validation error.
Constraints
- Clarify "one character": substitution only, or also insert/delete (edit distance ≤ 1)? Case/whitespace normalization first? Ties when two catalog terms both match?
Example
- "tree wifi" → "free wifi" (one substitution). "tea wifi" → exception (distance 2).
Expected approach
- Exact-match via hash set first. Then a distance-≤1 check per catalog term with early exit: equal lengths → allow one mismatch; lengths differing by 1 → allow one skip (insert/delete); else fail fast. O(catalog × term length) — a full Levenshtein DP is overkill for threshold 1, and saying so scores points. Wrap as a small service: normalize → validate → correct or throw, with a clear exception contract for the vendor API.
asked …