As reported: DoorDash Senior Software Engineer onsite (Toronto, 2025), the last coding round, part 2 of 2 (part 1: names one letter swap away).
Given a string name and a list nameList, return the strings in nameList that need the fewest letter changes so that the string becomes an anagram of name. One change replaces one letter of the string with any other letter.
Example 1
name = "LeetCode"
nameList = ["Ldcrerpt", "Ecleptde", "Lretcpde"]
Output: ["Ecleptde"]
"Ecleptde" needs 1 change (its p must become an o); "Lretcpde" needs 2; "Ldcrerpt" needs 3.
Example 2
name = "Dasher"
nameList = ["shared", "Dash", "Rashes", "hasted", "DASHER"]
Output: ["shared", "DASHER"]
Clarifications
- Letters are compared case-insensitively; return the strings exactly as they appear in
nameList, in their original order. - Only strings of the same length as
namecan become its anagram by changing letters; ignore the others. If none has the same length, return[]. - If several strings tie for the fewest changes, return all of them.
Constraints: 1 ≤ name.length ≤ 100; 0 ≤ nameList.length ≤ 10^4; every string has 1 to 101 English letters.
Code runner format: one JSON value per line: name, then nameList. Implement fewestChangesToAnagram(name, nameList); the harness prints the list.