Unique Morse Code Words

International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, such as:

  • 'a' maps to ".-"
  • 'b' maps to "-..."
  • 'c' maps to "-.-."

For convenience, the full table for the 26 letters of the English alphabet is:

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

Given an array of strings words, each word can be written as a concatenation of the Morse code of each letter. We call such a concatenation the transformation of a word.

Return the number of different transformations among all words in words.

Example 1
Inputwords = ["gin","zen","gig","msg"]
Output2
The transformations are "--...-." for "gin" and "zen", and "--...--." for "gig" and "msg", so there are 2 different transformations.
Example 2
Inputwords = ["a"]
Output1
The only word has one transformation, so there is 1 different transformation.

Constraints

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

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate