X1502: Most Frequent Word

Problem Description

Write a method mostFrequentWord that receives an array of strings and returns the word that appears most frequently.

Method Signature:

public String mostFrequentWord(String[] words)

You must use a HashMap to:

  • Count the frequency of each word.
  • Return the word with the highest count.

Constraints

  • The words array contains at least one string.
  • Words consist of non-null, non-empty strings.
  • Case-sensitive: "Word" and "word" are different.
  • If multiple words share the highest frequency, return any one of them.

Documentation

Your Answer:

Feedback

Your feedback will appear here when you check your answer.