Word Groups
InterviewTime limit0.1sMemory limit1024 MB
Given N words over R letters, find the fewest letters so that every word contains at least one of the chosen letters.
- Level
Medium5 of 10
- Topics
- Bit manipulation, Brute force, String
- Solved
- No attempts yet
Problem
Adam wants to build a multidimensional crossword puzzle and has picked words for it. All of the words use only the first letters of the Latin alphabet. The words can have different lengths, and the same letter can appear more than once in a word.
Adam wants to split the words into groups so that each group has at least one letter that appears in every word of that group.
Find the minimum possible number of groups.
Input
The first line contains the number of words and the number of distinct letters used in the words (, ). Each of the next lines contains one word. A word consists of at most 50 uppercase letters of the Latin alphabet.
Output
Print one integer: the minimum possible number of groups.