#C12307. Word with Most Unique Characters
Word with Most Unique Characters
Word with Most Unique Characters
Given a non-empty string consisting of words separated by spaces, your task is to find the word which contains the highest number of unique characters. In case two or more words have the same number of unique characters, return the one that appears first in the string.
More formally, if the input string is \(s = w_1\ w_2\ \dots\ w_n\), for each word \(w_i\), let \(f(w_i)\) be the number of distinct characters. You need to output the word \(w_k\) for which \(f(w_k)\) is maximized and among those with the maximum value, \(w_k\) appears earliest in the string.
If the input string is empty, output an empty string.
inputFormat
The input is provided via standard input (stdin) as a single line containing a string of words separated by spaces. The string can be empty.
outputFormat
Print to standard output (stdout) the word with the highest number of unique characters. In case of a tie, output the first word with that property. If the input is empty, print an empty string.## sample
hello world algorithms are fun
algorithms