Nice solution. Although it does not use memoization, it still runs very fast. But I wonder if some extreme test case may lead to a slow runtime of this code and make it TLE? Because it seems to me that this code still runs in NP time according to big-o notation.
@weeyanghuang It's clearly pointed out by the problem statements that there are only lowercase letters (which is now removed), so here we should expand the 26 to 256 to blend into the new situation. Thanks for your feedback!
"abbbcbaaccacaacc" can be scrambled to "acaaaccabcabcbcb"
a | bbbcbaaccacaacc
a | (bbbcbaaccacaac c)
a | c | (bbbcbaacc acaac)
a | c | acaac | bbbcbaacc
a | c | a caac | (b bbcbaacc)
a | c | a | (c aac) | bbcbaac c | b
a | c | a | aac | c | (bbc baac) | c | b
a | c | a | aac | c | ba ac | (b bc) | c | b
a | c | a | aac | c | (b a) | (a c) | bc | b | c | b
a | c | a | aac | c | a | b | c | a | bc | b | c | b
"hobobyrqd" can be scrambled to "hbyorqdbo"
h | (ob obyrqd)
h | oby rqd | (o b)
h | (o by) | rqd | b | o
h | by | o | rqd | b | o