Show problems as
Classic problem #804EasyArrayHash TableString

Unique Morse Code Words

Real-world version: Distinct Flag Strings for the Signal Words
Tracked in this browser only
Read Unique Morse Code Words on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

A signal book gives each lowercase letter a fixed flag pattern. Letter 'a' uses the pattern ".-", and the twenty-six patterns in letter order are

[".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."].

A word is signalled by writing the patterns of its letters one after another with nothing between them, which is called its flag string.

Return how many different flag strings the words of words produce.

Examples

Example 1

Input
words = ["ee", "i"]
Output
1

Letter "e" is a single dot and letter "i" is two dots, so both words signal ".." and only one flag string comes out.

Example 2

Input
words = ["a", "b"]
Output
2

The two letters have different patterns, so the two words signal different flag strings.

Example 3

Input
words = ["ab", "ab", "ba"]
Output
2

The two copies of the first word signal the same flag string, and reversing the letters gives a different one, so two come out.

Constraints

  • 1 <= words.length <= 100
  • 1 <= words[i].length <= 12
  • words[i] consists of lowercase English letters only

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def distinct_flag_strings(words: list[str]) -> int:
Java
public int distinctFlagStrings(String[] words)