bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
MediumArrays & HashingLC 288

Unique Word Abbreviation

The abbreviation of a word is a concatenation of its first letter, the number of characters between the first and last letter, and its last letter. If a word has only two characters, then it is an abbreviation of itself. For example: dog --> d1g because there is one letter between the first letter 'd' and the last letter 'g'. internationalization --> i18n because there are 18 letters between the first letter 'i' and the last letter 'n'. it --> it because any word with only two characters is an abbreviation of itself. Implement the ValidWordAbbr class: ValidWordAbbr(String[] dictionary) Initializes the object with a dictionary of words.

Asked at 1 company
Google
Hints
  • 1.Think about which data structure fits best
  • 2.Consider the time complexity of your approach
  • 3.Look for patterns in the constraints
LeetCode