Candidate Alias Name Matching
Problem statement
Given a list of known candidate aliases and a name returned on a record, return whether the record name matches at least one alias.
Names contain a first name, an optional middle name or initial, and a last name. Last names must match exactly. A missing middle name is compatible with any middle name. A one-letter middle initial matches a middle name with the same initial. The first and middle names may be transposed; the last name may not move.
Object-model variation
Another reported interview asks for a Name class whose constructor takes a name string and parses its first, optional middle, and last parts, with __eq__(other) implementing name matching.
For this practice variation, use the matching rules above for two parsed names. The graded interface remains nameMatch(knownAliases, recordName); the class variation is a follow-up.
Function
nameMatch(knownAliases: String[], recordName: String) → booleanExamples
Example 1
knownAliases = ["Alphonse Gabriel Capone","Al Capone"]recordName = "Alphonse Gabriel Capone"return = trueThe record exactly matches the first alias.
Example 2
knownAliases = ["Alphonse Gabriel Capone"]recordName = "Gabriel A Capone"return = trueThe first and middle names are transposed and the initial matches Alphonse.
Constraints
1 <= knownAliases.length <= 1000.- Every name has two or three non-empty space-separated parts.
- Matching is case-sensitive.
- For this exercise, assume every part contains ASCII letters and parts are separated by exactly one ASCII space, with no leading or trailing spaces.