A word is grouped if, for each letter in the word, all occurrences of that letter form exactly one consecutive sequence. In other words, no two equal letters are separated by one or more letters that are different. For example, the words "ccazzzzbb" and "code" are grouped, while "aabbbccb" and "topcoder" are not.
A grouped word was divided into several parts. You are given all the parts in random order as a String[]. Reconstruct the original word and return it. If there is more than one possible answer, return "MANY" instead. If no grouped word could have resulted in the given parts, return "IMPOSSIBLE" instead (all quotes for clarity).
|