TopCoder problem "SyllableCounter" used in SRM 248 (Division II Level One)

Problem Statement

    In the English language, a syllable can be loosely defined as a unit of uninterrupted sound. One can usually count the number of syllables in an English word by 'sounding it out'. In general, however, it is difficult to write a program to count the number of syllables in a word.

Here, we'll use the following procedure to count syllables: Each group of vowels {'A', 'E', 'I', 'O', 'U'} appearing in the word will add one syllable to the total number of syllables in the word. A group of vowels is either separated by consonants (all letters A-Z that are not vowels) or the group appears at the beginning or end of the word. So, for example, the word "HELLO" contains 2 syllables according to the above procedure due to the vowels 'E' and 'O'. The word "FOOBAR" also contains 2 syllables, even though there are 3 vowels in the word. This is because the two 'O' vowels are considered one group of vowels. Finally, the word "TELEVISION" contains 4 syllables.

Create a class SyllableCounter containing a method countSyllables which takes a String word as input. The method should return an int corresponding to the number of syllables in word according to the above algorithm.


Method signature:int countSyllables(String word)
(be sure your method is public)


-word will contain between 3 and 50 characters inclusive.
-word will contain only uppercase letters ('A'-'Z').
-word will contain at least one vowel and at least one consonant.


Returns: 3
Note that this returns 3 because of the vowels O, U, and E. Your method should return 3 despite the fact that in spoken English, the E at the end doesn't actually create a syllable.
Returns: 4
Returns: 3
Returns: 5

Problem url:

Problem stats url:




PabloGilberto , lbackstrom , brett1479

Problem categories:

String Manipulation