Parse a string into brand, model and generation
Task
You have a string like "BMW 5 series e39" and reference lists: the brand's known models and generations. Return (brand, model, generation). The catch: a model may be several words ("5 series") and may be a prefix of another ("5" and "5 series"). Any part may be missing.
let models = ["5 series", "3", "5", "7", "9"]
let generations = ["e39", "g30"]
The rest of this answer, with code and interview follow-ups, is in the DevPrep app.
Read the full answer in DevPrep