You are given a list of words. You need to find the shortest prefix of each word so that it can identify the word uniquely.
Words: ["program", "code", "process", "coding", "type", "print"]
Output: ["prog", "code", "proc", "codi", "t", "pri"]
Note: Assume, no word is prefix of another. Hence, a unique prefix is always possible.
The input contains the following lines:
Space-separated strings, each denoting the shortest prefix identifying its respective word.
6
program code process coding type print
prog code proc codi t pri
1 <= n <= 105
1 <= word length <= 10
Words have only lower-case characters (a-z).