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.
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each testcase contains a string.
Print the word with the maximum frequency and the frequency, both separated by a space. See example for more clarity.
the devil in the sky
amazon is amazon geeks for geeks is geeks for geeks
this is not right
the phenomenal one
For testcase 1: The frequency of the is 2, so we print the and its frequency
For testcase 3: Every word has the frequency of 1, so we print this 1 as this occurs first in the sentence
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.