Connection Status:
Competition Arena > GroupedWordChecker
SRM 432 · 2009-01-06 · by nika · Simple Search, Iteration, String Manipulation
Class Name: GroupedWordChecker
Return Type: int
Method Name: howMany
Arg Types: (vector<string>)
Problem Statement

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 String[]. Return how many of them are grouped.

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.
Examples
0)
{"ccazzzzbb", "code", "aabbbccb", "topcoder"}
Returns: 2

As mentioned in the problem statement, the first two words are grouped.

1)
{"ab", "aa", "aca", "ba", "bb"}
Returns: 4

"aca" is not a grouped word.

2)
{"happy", "new", "year"}
Returns: 3
3)
{"yzyzy", "zyzyz"}
Returns: 0
4)
{"z"}
Returns: 1

Submissions are judged against all 75 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

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

Submitting as anonymous