Unique Morse Code Words
Real-world version: Distinct Flag Strings for the Signal WordsThe 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.
def distinct_flag_strings(words: list[str]) -> int:public int distinctFlagStrings(String[] words)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 11 test cases: 11 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Verifying an Alien DictionaryReal-world version: Catalogue Order Under a Custom Glyph SequenceEasy
- Find Common CharactersReal-world version: Tiles Every Rack Can SupplyEasy
- Destination CityReal-world version: Last Stop On The Courier RunEasy
- Find Words That Can Be Formed by CharactersReal-world version: Signs Spellable From A Tile TrayEasy