All English Decodings of Morse Code
Updated
Problem statement
You are given a string morse made of the characters . (dot) and - (dash). It is the Morse code of a sequence of English letters, written with the codes from the table below. The codes of the letters are written one right after another, with no spaces or other separators between them, so one string can come from more than one sequence of letters.
Return every string of lowercase letters whose codes, written one after another, give exactly morse. Return the strings in lexicographic (dictionary) order. Any sequence of letters counts; it does not have to be a real English word.
| Letter | Code | Letter | Code |
|---|---|---|---|
a | .- | n | -. |
b | -... | o | --- |
c | -.-. | p | .--. |
d | -.. | q | --.- |
e | . | r | .-. |
f | ..-. | s | ... |
g | --. | t | - |
h | .... | u | ..- |
i | .. | v | ...- |
j | .--- | w | .-- |
k | -.- | x | -..- |
l | .-.. | y | -.-- |
m | -- | z | --.. |
Function
decodeAll(morse: String) → List<String>Examples
Example 1
morse = ".-"return = ["a","et"].- is the code of a. It can also be read as . (e) followed by - (t). In lexicographic order the answer is ["a","et"].
Example 2
morse = "..."return = ["eee","ei","ie","s"]A | marks where one letter code ends and the next begins. Three dots can be cut as .|.|. (eee), .|.. (ei), ..|. (ie) or ... as one piece (s). Sorted: ["eee","ei","ie","s"].
Example 3
morse = "-.-"return = ["k","nt","ta","tet"]-.- is k. Cut as -.|- it is nt, as -|.- it is ta, and as -|.|- it is tet. The code of c, -.-., is longer than the whole string, so c cannot be used.
Constraints
1 <= morse.length <= 10morseconsists only of the characters.and-.
More Oscar Health interview questions
Similar questions at other companies
- Largest Number Below N from Reusable DigitsByteDance · PHONE SCREENByteDance interview questions
- Phone-Number Letter CombinationsHeadway · PHONE SCREENHeadway interview questions
- Letter Combinations of a Phone NumberLinkedIn · PHONE SCREENLinkedIn interview questions
- String Permutations in Custom Character OrderWex · OA · PHONE SCREEN
- Numeric Poker OperationsRippling · PHONE SCREENRippling interview questions
- Unique String PermutationsAmazon · PHONE SCREEN
- Permutations of Unique CharactersSalesforce · PHONE SCREENSalesforce interview questions
- Count Prefix Paths in a Character GraphGoogle · PHONE SCREENGoogle interview questions
- Sorted Subsets of a StringMicrosoft · PHONE SCREENMicrosoft interview questions
- Maximum Unique Substring SplitThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions