/320. Generalized Abbreviation

320. Generalized Abbreviation

Medium
Strings60.4% acceptance

Given a string input_str, generate all possible generalized abbreviations of input_str. In a generalized abbreviation, each substring of consecutive characters can be replaced by their count. Return all possible abbreviations as a list of strings.

Example 1

Input: abc

Output: [abc, ab1, a1c, a2, 1bc, 1b1, 2c, 3]

Explanation: All possible abbreviations for abc.

Example 2

Input: dog

Output: [dog, do1, d1g, d2, 1og, 1o1, 2g, 3]

Explanation: All possible abbreviations for dog.

Constraints

  • 1 <= len(input_str) <= 20
  • input_str consists of lowercase English letters only
Python (current runtime)

Case 1

Input: 'xyz'

Expected: ['xyz', 'xy1', 'x1z', 'x2', '1yz', '1y1', '2z', '3']

Case 2

Input: 'abcd'

Expected: ['abcd', 'abc1', 'ab1d', 'ab2', 'a1cd', 'a1c1', 'a2d', 'a3', '1bcd', '1bc1', '1b1d', '1b2', '2cd', '2c1', '3d', '4']