Alphanumeric Abbreviations of a String

Given a string of characters of length less than 10, return all the alpha-numeric abbreviations of the string (in lexicographic order).

The alpha-numeric abbreviation is in the form of characters mixed with the digits which is equal to the number of skipped characters of a selected substring. So, whenever a substring of characters is skipped, you have to replace it with the digit denoting the number of characters in the substring. There may be any number of skipped substrings of a string. No two substrings should be adjacent to each other. Hence, no two digits are adjacent in the result. For a clearer idea, see the example.


"ANKS" should return ["1N1S", "1N2", "1NK1", "1NKS", "2K1", "2KS", "3S", "4", "A1K1", "A1KS", "A2S", "A3", "AN1S", "AN2", "ANK1", "ANKS"].

Note that "11KS" is not valid because no two digits should be adjacent, however "2KS" is valid.

Contributed by Berkan Teber