FastPrepUnique Morse Code Words
Problem · Hash Table

Unique Morse Code Words

Learn this problem
EasyAmazon logoAmazonINTERNONSITE INTERVIEW
See Amazon hiring insights

Problem statement

Each lowercase English letter maps to the following International Morse code string, in alphabet order from a through z:

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

The transformation of a word is the concatenation of the Morse strings for its letters. Given words, return the number of distinct transformations.

Function

uniqueMorseRepresentations(words: String[]) → int

Examples

Example 1

words = ["gin","zen","gig","msg"]return = 2

gin and zen share one transformation, while gig and msg share another.

Example 2

words = ["a"]return = 1

A single word contributes one distinct transformation.

Example 3

words = ["no","on"]return = 2

The two letter orders produce different concatenated Morse strings.

Constraints

  • 1 <= words.length <= 100.
  • 1 <= words[i].length <= 12.
  • Every word contains only lowercase English letters.

More Amazon problems

drafts saved locally
public int uniqueMorseRepresentations(String[] words) {
  // write your code here
}
words["gin","zen","gig","msg"]
expected2
checking account