Decode Ambiguous Morse Messages
SealthSoftware Engineer · Technical ScreenLast updated
This question evaluates string parsing, pattern matching, and combinatorial decoding skills using a Morse-to-letter mapping, covering both deterministic separator handling and enumeration of ambiguous letter partitions.
You are given a mapping from Morse patterns to lowercase English letters.
Implement two related functions:
- Deterministic decoding with character and word separators
- Input: a Morse-encoded string, a
char_septhat separates letters inside a word, and aword_septhat separates words. - Output: the decoded sentence.
- Example: if
char_sepseparates letters andword_sepseparates words, decode the full message by splitting on words first and then on characters.
- Enumerate all valid decodings when character separators are missing
- Input: a Morse-encoded string that contains only a
word_sepbetween encoded words, but no separator between letters inside each word. - Because each encoded word may be partitioned into letters in multiple valid ways, return all possible decoded sentences as a list or set.
- For each encoded word, generate every valid letter sequence whose Morse concatenation matches that word exactly, then combine the per-word results into full-sentence outputs.
Assume the Morse-to-letter dictionary is provided as part of the problem.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.