← Questions
Unique Morse code words
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Amazon's technical phone screen, last asked Feb 2026. It tests strings and hash sets.
Each letter a–z has a Morse code: a is .-, b is -..., c is -.-., and so on through z (--..). A word's translation is its letters' codes joined with no separators, so different words can share a translation. Given a list of words, return how many different translations there are.
Interface
Unless you agree on a different interface with the interviewer, assume:
-
unique_morse(words: list[str]) -> int— the 26 codes are given as a list in alphabetical order.
Example
"cab" -> "-.-." + ".-" + "-..." = "-.-..--..."
unique_morse(["gin", "zen", "gig", "msg"]) -> 2 # gin and zen are "--...-."; gig and msg are "--...--."
unique_morse(["a", "et", "n", "te"]) -> 2 # ".-" twice and "-." twice
unique_morse(["a"]) -> 1
Constraints
- Up to 100 words of 1 to 12 lowercase letters.
Clarifying questions
- Is the code table given, or should I write it out?
- Only lowercase letters?
- An empty list returns
0?
What a strong answer covers
- Index the table with
ord(ch) - ord('a'), build each translation with a join, and count with a set. - O(total letters) time and space.
- Why translations collide: Morse needs gaps between letters to be decodable.
Follow-ups
- Group the words by translation.
- Given a Morse string with no gaps, count the words from a dictionary it could spell.
- Decode a gapless Morse string into every possible letter string (backtracking with memoization).
Where it's asked
- Amazon · Technical phone screen · Last asked Feb 202660 min · Live coding in a shared editor that does not run code, plus Leadership Principles questions · No AI
What it tests
strings · hash sets
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
