![]() |
VOOZH | about |
Given a string which contains multiple words, our task is to find the word which has highest number of repeating characters.
Examples:
Input: str = "hello world programming"
Output: "programming"
Explanation: The word "programming" has the highest number of repeating characters, with 'r', 'g', and 'm' each appearing twice.Input: str= "jumping foxes swiftly"
Output: -1
Explanation: No word has any repeating character.
Note - If multiple words in the string have the highest number of repeating characters, return the one that appears first.
The idea is to iterate each word and count the frequency of each character in the word. Finally, the word with the most repeated characters will be our result.
Step-by-step approach:
programming
Time Complexity: O(n)
Auxiliary Space: O(1)