Solve Two String Problems
Company: Amazon
Role: Data Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Technical Screen
Quick Answer: This task evaluates string manipulation and encoding for generating unique Morse representations, along with sentence segmentation and combinatorial enumeration for producing all valid word-break sentences, focusing on transformation, deduplication, and decomposition skills.
Part 1: Unique Morse Code Transformations
Constraints
- 0 <= len(words) <= 100
- 1 <= len(words[i]) <= 12 for every word when the list is non-empty
- Each word contains only lowercase English letters
Examples
Input: (["gin", "zen", "gig", "msg"],)
Expected Output: 2
Explanation: gin and zen share one translation, while gig and msg share another.
Input: (["a"],)
Expected Output: 1
Explanation: A single word always contributes exactly one translation.
Input: ([],)
Expected Output: 0
Explanation: With no words, there are no translations.
Input: (["a", "a", "a"],)
Expected Output: 1
Explanation: Repeated identical words do not create new distinct Morse strings.
Hints
- Store the Morse code for letters a to z in an array so you can index it with ord(ch) - ord('a').