Decode Ambiguous Morse Messages
Problem Description
You are tasked with implementing two distinct but related functions for decoding Morse code messages, given a predefined mapping from Morse patterns to lowercase English letters.
Function 1: Deterministic Decoding
Implement a function that performs deterministic decoding of a Morse-encoded string.
- Input: A Morse-encoded string, a
char_sepstring that acts as a separator between individual letters within a word, and aword_sepstring that separates entire words. - Output: The fully decoded English sentence.
- Decoding Logic: The message should be decoded by first splitting the input string into words using the
word_sep, and then splitting each word into individual character Morse patterns using thechar_sep.
Function 2: Ambiguous Decoding
Implement a function that enumerates all possible valid decodings for a Morse-encoded string where character separators are missing.
- Input: A Morse-encoded string that contains only a
word_sepbetween encoded words, but crucially, no separator between letters within each word. - Output: A list or set of all possible decoded English sentences.
- Decoding Logic: Due to the absence of character separators, each encoded word may be partitioned into letters in multiple valid ways. For each encoded word, you must generate every valid sequence of letters whose concatenated Morse patterns exactly match that word. Subsequently, combine these per-word results to form all possible full-sentence outputs.
Assumption
The Morse-to-letter dictionary (mapping Morse patterns to lowercase English letters) will be provided as part of the problem context.
AI interview prep
Core dilemma
Managing combinatorial explosion and efficient enumeration of all valid interpretations for ambiguously encoded segments, while ensuring correctness and performance.
3 tradeoffs and 2 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Decode Ambiguous Morse Messages
Problem Description
You are tasked with implementing two distinct but related functions for decoding Morse code messages, given a predefined mapping from Morse patterns to lowercase English letters.
Function 1: Deterministic Decoding
Implement a function that performs deterministic decoding of a Morse-encoded string.
- Input: A Morse-encoded string, a
char_sepstring that acts as a separator between individual letters within a word, and aword_sepstring that separates entire words. - Output: The fully decoded English sentence.
- Decoding Logic: The message should be decoded by first splitting the input string into words using the
word_sep, and then splitting each word into individual character Morse patterns using thechar_sep.
Function 2: Ambiguous Decoding
Implement a function that enumerates all possible valid decodings for a Morse-encoded string where character separators are missing.
- Input: A Morse-encoded string that contains only a
word_sepbetween encoded words, but crucially, no separator between letters within each word. - Output: A list or set of all possible decoded English sentences.
- Decoding Logic: Due to the absence of character separators, each encoded word may be partitioned into letters in multiple valid ways. For each encoded word, you must generate every valid sequence of letters whose concatenated Morse patterns exactly match that word. Subsequently, combine these per-word results to form all possible full-sentence outputs.
Assumption
The Morse-to-letter dictionary (mapping Morse patterns to lowercase English letters) will be provided as part of the problem context.