Quick Overview

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.

Decode Ambiguous Morse Messages

Company: Sealth

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given a mapping from Morse patterns to lowercase English letters. Implement two related functions: 1. **Deterministic decoding with character and word separators** - Input: a Morse-encoded string, a `char_sep` that separates letters inside a word, and a `word_sep` that separates words. - Output: the decoded sentence. - Example: if `char_sep` separates letters and `word_sep` separates words, decode the full message by splitting on words first and then on characters. 2. **Enumerate all valid decodings when character separators are missing** - Input: a Morse-encoded string that contains only a `word_sep` between 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.

Quick Answer: 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.

Decode Morse With Separators

Decode a Morse message using explicit character and word separators.

Constraints

  • Inputs are Python literals matching the function signature.
  • Return a deterministic exact-match value.

Examples

Input: ('.... . .-.. .-.. --- / .-- --- .-. .-.. -..', ' ', ' / ', {'....':'h','.':'e','.-..':'l','---':'o','.--':'w','.-.':'r','-..':'d'})

Expected Output: 'hello world'

Explanation: Decode with explicit character and word separators.

Input: ('', ' ', '/', {'.':'e'})

Expected Output: ''

Explanation: An empty encoded message decodes to the empty string.

Hints

  1. Clarify edge cases before coding.
  2. Keep the return value deterministic.

Enumerate Morse Decodings Without Character Separators

Return all decoded sentences when letters inside each word are not separated; output is sorted for deterministic grading.

Constraints

  • Inputs are Python literals matching the function signature.
  • Return a deterministic exact-match value.

Examples

Input: ('....../.-', '/', {'.':'e','-':'t','....':'h','..':'i','...':'s','.-':'a'})

Expected Output: ['eeeeee a', 'eeeeee et', 'eeeei a', 'eeeei et', 'eeeie a', 'eeeie et', 'eees a', 'eees et', 'eeh a', 'eeh et', 'eeiee a', 'eeiee et', 'eeii a', 'eeii et', 'eese a', 'eese et', 'ehe a', 'ehe et', 'eieee a', 'eieee et', 'eiei a', 'eiei et', 'eiie a', 'eiie et', 'eis a', 'eis et', 'esee a', 'esee et', 'esi a', 'esi et', 'hee a', 'hee et', 'hi a', 'hi et', 'ieeee a', 'ieeee et', 'ieei a', 'ieei et', 'ieie a', 'ieie et', 'ies a', 'ies et', 'ih a', 'ih et', 'iiee a', 'iiee et', 'iii a', 'iii et', 'ise a', 'ise et', 'seee a', 'seee et', 'sei a', 'sei et', 'sie a', 'sie et', 'ss a', 'ss et']

Explanation: Enumerate all decodings for each separator-delimited word.

Input: ('', '/', {'.':'e'})

Expected Output: ['']

Explanation: Empty encoded input has one empty sentence.

Hints

  1. Clarify edge cases before coding.
  2. Keep the return value deterministic.

Loading coding console...