Skip to content

Practice Unique Morse Code Words

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#804
LeetCode Problem

Unique Morse Code Words

Problem Statement

Encode each lowercase word by concatenating its letters' Morse codes with no separator. Return how many distinct encoded strings occur; different words may encode identically. The alphabet mapping, from a through z, is: .-, -..., -.-., -.., ., ..-., --., ...., .., .---, -.-, .-.., --, -., ---, .--., --.-, .-., ..., -, ..-, ...-, .--, -..-, -.--, --.. Practice approach: Store the 26 mappings in alphabet order. Build each word's encoding, insert it into a set, and return the set size. With L input characters, encoding requires O(L) time and at most O(L) storage.

Source: Unique Morse Code Words on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
words = ["a", "et", "b"]
Output
2
Explanation

Both a and et encode as .-. The encoding of b is -..., giving two distinct strings.

Constraints

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

Related LeetCode Problems

Practice more problems similar to Unique Morse Code Words.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.