GroupedWord
SRM 432 · 2009-01-06 · by nika
Problem Statement
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
Constraints
- parts will contain between 1 and 50 elements, inclusive.
- Each element of parts will contain between 1 and 20 characters, inclusive.
- Each element of parts will contain only lowercase letters ('a' - 'z').
{"aaa", "a", "aa"}
Returns: "aaaaaa"
These parts could only have come from the word "aaaaaa", which is a grouped word.
{"ab", "bba"}
Returns: "IMPOSSIBLE"
The only possible original words are "abbba" and "bbaab", and neither of them are grouped words.
{"te", "st"}
Returns: "stte"
{"te", "s", "t"}
Returns: "MANY"
The initial word could be either "stte" or "ttes".
{"orr", "rd", "woo", "www"}
Returns: "wwwwooorrrd"
Submissions are judged against all 229 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class GroupedWord with a public method string restore(vector<string> parts) · 229 test cases · 2 s / 256 MB per case