All problems
0868EasyArrayHash TableString

Distinct Flag Strings for the Signal Words

Tracked in this browser only
Write code

Trains the technique from

LeetCode 804Unique Morse Code Words

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

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