#K55367. Taco Subset: Find the Shortest Containing Word

    ID: 29960 Type: Default 1000ms 256MiB

Taco Subset: Find the Shortest Containing Word

Taco Subset: Find the Shortest Containing Word

Given a list of n words and a string of characters, your task is to determine the shortest word in the list that contains all the characters from the given string. A word is said to contain all the characters if for every character c in the given string (with multiplicity), the word contains at least as many occurrences of c.

If no such word exists, output an empty string.

Note: The characters can appear in any order in the word.

inputFormat

The input is read from standard input and consists of three lines:

  • The first line contains a single integer n representing the number of words.
  • The second line contains n words separated by spaces.
  • The third line contains a string of characters. This string may be empty.

outputFormat

Output the shortest word that contains all the characters from the given string. If there is no such word, output an empty string.

## sample
5
step steps stripe stepple stepladder
ppe
stepple

</p>