Abbreviation Generator

Solve a hard-level problem of creating unique abbreviations of input strings using tries.

Problem statement

In this problem, you'll be developing an abbreviation generator. The initial abbreviation for a string is the first character, then the number of characters in between, followed by the last character.

When given a list of words, if more than one word shares the same abbreviation, perform the following operation: increase the prefix (characters in the first part) of each of their abbreviations by 1.

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. In the end, if an abbreviation does not shorten a word, then keep it as the original word.

Given an array of distinct string words, generate and return the minimal possible and unique abbreviations for every word.

Example 1

Sample input

Get hands-on with 1400+ tech skills courses.