LC: 1153. String Transforms Into Another String - spiralgo/algorithms GitHub Wiki

1153. String Transforms Into Another String:

The Essence:

A string is not convertible to another string under these 2 conditions:

  1. A character transforms into more than one character:

"aaa" -> "hgf" is not possible.

  1. The second string contains all possible letters: When both strings contain same letters as in: "abc" -> "bca", we can convert individual letters without making them the same by temporarily converting them to another letter like this:

"abc" -> "dbc" -> "dba" -> "dca" -> "bca" As long as we have a letter not present in the destination string, we can do such temporary conversions.

We only have to check for these.

Details:

Please refer to the corresponding PR for an implementation of this intuition:

https://github.com/spiralgo/algorithms/pull/388