class Solution
{
//Function to find most frequent word in an array of strings.
public String mostFrequentWord(String arr[],int n)
{
String ans = "";
HashMap<String, Integer> mp = new HashMap<>();
for(int i=n-1; i >= 0; i--){
String s = arr[i];
mp.put(s, mp.getOrDefault(s, 0) + 1);
if(mp.get(s) > mp.getOrDefault(ans, 0)){
ans = s;
}
}
return ans;
}
}