GroupedWordChecker
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.
You are given several words as a
Constraints
- words will contain between 1 and 50 elements, inclusive.
- Each element of words will contain between 1 and 50 characters, inclusive.
- Each element of words will contain only lowercase letters ('a' - 'z').
- All elements of words will be distinct.
{"ccazzzzbb", "code", "aabbbccb", "topcoder"}
Returns: 2
As mentioned in the problem statement, the first two words are grouped.
{"ab", "aa", "aca", "ba", "bb"}
Returns: 4
"aca" is not a grouped word.
{"happy", "new", "year"}
Returns: 3
{"yzyzy", "zyzyz"}
Returns: 0
{"z"}
Returns: 1
Submissions are judged against all 75 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class GroupedWordChecker with a public method int howMany(vector<string> words) · 75 test cases · 2 s / 256 MB per case