Delimited Morse Decoding and Word Segmentation
Updated
Problem statement
Decode an uppercase-English Morse message that uses the literal string xxx between encoded letters.
- When
sharedDelimiteris false,xxxxxseparates words. Return the single decoded lowercase sentence. - When
sharedDelimiteris true, every separator isxxx. Decode the continuous lowercase letter string, then return every sentence obtainable by splitting it into words fromdictionary.
Return sentences in lexicographic order. Dictionary words are unique lowercase strings. The encoded input is valid Morse for letters A–Z. Empty input decodes to one empty sentence.
Function
decodeDelimitedMorse(encoded: String, dictionary: String[], sharedDelimiter: boolean) → String[]Examples
Example 1
encoded = ".-xxx-..xxxxx..-"dictionary = []sharedDelimiter = falsereturn = ["ad u"].-, -.., and ..- decode to A, D, and U; five x characters separate the two words.
Example 2
encoded = ".-xxx-..xxx..-"dictionary = ["ad","u","a","du"]sharedDelimiter = truereturn = ["a du","ad u"]The decoded letters are adu, which have two valid dictionary segmentations.
Example 3
encoded = ""dictionary = []sharedDelimiter = falsereturn = [""]The empty message contains one empty sentence.
Constraints
0 <= encoded.length <= 2000.0 <= dictionary.length <= 5000.- Dictionary words are unique lowercase English strings with length from
1through100. - At most
10000valid sentences exist.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- First Valid Word SegmentationAmazon · ONSITE INTERVIEW
- Word Break IIBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Word Break II: All SentencesMicrosoft · PHONE SCREEN · ONSITE INTERVIEWMicrosoft interview questions
- All Palindrome PartitionsExpedia · OAExpedia interview questions
- Palindrome PartitioningLondon Stock Exchange · PHONE SCREENLondon Stock Exchange interview questions
- Word Break IIWex · PHONE SCREEN
- Word Break IIInMobi · PHONE SCREENInMobi interview questions
- Count Complete Tic-Tac-Toe GamesDecagon · PHONE SCREEN · ONSITE INTERVIEWDecagon interview questions
- Maximum Bouquet ValueOracle · ONSITE INTERVIEWOracle interview questions
- Word BreakMoveworks · ONSITE INTERVIEWMoveworks interview questions