Copied to Clipboard
Word with maximum frequency
Easy Accuracy: 39.39% Submissions: 3860 Points: 2

You are given a string that is made up of words separated by spaces. Your task is to find the word with highest frequency, i.e. it appears maximum times in the sentence. If multiple words have maximum frequency, then print the word that occurs first in the sentence.

Example 1:

Input : S = "the devil in the sky"
Output : the 2
The frequency of the is 2, so we return "the" and
its frequency "2" i.e., "the 2" 

Example 2:

Input : S = "this is not right"
Output : this 1
Every word has the frequency of "1", so we return 
"this 1" as this occurs first in the sentence. 

Your Task:
This is a function problem. The input is already taken care of by the driver code. You only need to complete the function maximumFrequency() that takes a string S and return the answer as a string. The driver code takes care of the printing.

Expected Time Complexity: O(N).
Expected Auxiliary Space: O(N).

1 ≤ |S| ≤ 105

to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.

Word with maximum frequency

Output Window