Unique Word Abbreviation
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
A word's **abbreviation** is its first letter, then the count of letters strictly between the first and last, then its last letter. For example "dog" becomes "d1g" and "internationalization" becomes "i18n". A word with fewer than 3 letters is its own abbreviation ("it" stays "it").
Implement ValidWordAbbr(dictionary), where dictionary may contain duplicates, and isUnique(word).
isUnique(word) returns true if no dictionary word shares word's abbreviation, or if every dictionary word that shares it is exactly word itself. Otherwise it returns false. word does not need to be in the dictionary.
Examples
Constraints
- 1 <= dictionary.length <= 3 * 10^4
- 1 <= dictionary[i].length, word.length <= 20
- All words consist of lowercase English letters
- At most 5000 calls to `isUnique`
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.