TopcoderArchiveVisit Topcoder
Archive
Algorithm problem

FrequentWord

Problem statement, definition, constraints, and public examples.

Problem Statement

Given a list of strings, your method should find the word that occurs most frequently in the list. The given strings will be single space delimited lists of words. The words will be comprised of only lowercase ('a'-'z') and uppercase ('A'-'Z') letters. When comparing words for equality, the comparison must be CASE-INSENSITVE. This means (quotes for clarity) "abba" is equivalent to "AbbA". Your method will return the number of times the most frequently used word occurs.

Definition

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

Constraints

  • wordlist will contain between 1 and 50 elements inclusive.
  • Each element of wordlist will contain between 1 and 50 characters inclusive.
  • Each element of wordlist will contain no leading or trailing whitespace.
  • Each element of wordlist will contain only lowercase letters ('a'-'z'), uppercase letter ('A'-'Z'), or spaces (' ').
  • The elements of wordlist will be single space delimited lists of words. Each word will contain only letters.

Examples

  1. {"Wow wow hmm hmmm",
     "wow WOW hmm cow"}
    Returns: 4
    The word wow occurs 4 times in various cases.
  2. {"AAA","AAa","AaA","Aaa","aAA",
     "aAa","aaA","aaa"}
    Returns: 8
    The word aaa occurs 8 times in all possible cases.
  3. {"a"}
    Returns: 1
    Just a.
  4. {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
     "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAb",
     "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAc"}
    Returns: 1
    Sometimes words are long.
Back to all problems