Unique Morse Code Words

International Morse Code maps each letter to a series of dots and dashes: "a" -> ".-", "b" -> "-...", "c" -> "-.-.", and so on. The transformation of a word is the concatenation of the codes of its letters, for example "cab" -> "-.-..--...". Given an array of strings words, return the number of different transformations among all words.

30:00

Unique Morse Code Words
easy
Free written solution
Topics
Companies

International Morse Code maps each letter to a series of dots and dashes: "a" -> ".-", "b" -> "-...", "c" -> "-.-.", and so on. The transformation of a word is the concatenation of the codes of its letters, for example "cab" -> "-.-..--...". Given an array of strings words, return the number of different transformations among all words.

Example 1:
Input: {"words":["gin","zen","gig","msg"]}
Output: 2
Constraints:
  • 1≤words.length≤1001 \leq \text{words.length} \leq 100

  • 1≤words[i].length≤121 \leq \text{words}[i].\text{length} \leq 12

  • words[i]\text{words}[i] consists of lowercase English letters.

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"words":["gin","zen","gig","msg"]}

Each of the 4 words becomes one long string of dots and dashes. Different words can produce the same string, because the letter boundaries disappear once the codes are glued together.

words (4)

gin

waiting

zen

waiting

gig

waiting

msg

waiting

seen (set of transformations)

size = 0

empty

Variables
VariableValue
words4
distinct0
DepthFunction Call
Stack empty
0/21