bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
HardArrays & HashingLC 527

Word Abbreviation

Given an array of distinct strings words, return the minimal possible abbreviations for every word. The following are the rules for a string abbreviation:

  1. The initial abbreviation for each word is: the first character, then the number of characters in between, followed by the last character.
  2. If more than one word shares the same abbreviation, then perform the following operation: Increase the prefix (characters in the first part) of each of their abbreviations by
  3. For example, say you start with the words [ "abcdef ", "abndef "] both initially abbreviated as "a4f ". Then, a sequence of operations would be [ "a4f ", "a4f "] -> [ "ab3f ", "ab3f "] -> [ "abc2f ", "abn2f "]. This operation is repeated until every abbreviation is unique. 3.
Asked at 4 companies
GoogleGrabSnapchat
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