TopcoderArchiveVisit Topcoder
SRM6 Jan 2009
SRM 432

GroupedWordChecker

Problem statement, definition, constraints, and public examples.

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.

Definition

Class:
GroupedWordChecker
Method:
howMany
Parameters:
String[]
Returns:
int
Method signature:
int howMany(String[] words)
(be sure your method is public)

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

  1. {"ccazzzzbb", "code", "aabbbccb", "topcoder"}
    Returns: 2
    As mentioned in the problem statement, the first two words are grouped.
  2. {"ab", "aa", "aca", "ba", "bb"}
    Returns: 4
    "aca" is not a grouped word.
  3. {"happy", "new", "year"}
    Returns: 3
  4. {"yzyzy", "zyzyz"}
    Returns: 0
  5. {"z"}
    Returns: 1
Back to all problems