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.
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
words = ["a", "et", "b"]
2
Both a and et encode as .-. The encoding of b is -..., giving two distinct strings.
Constraints
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.