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

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`

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=10295

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=13694&pm=10295

nika

Testers:

PabloGilberto , Olexiy , ivan_metelsky

Problem categories:

Simple Search, Iteration, String Manipulation