Solve two string DP/hash problems
Company: Amazon
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Technical Screen
Quick Answer: This question set evaluates string-processing and algorithmic problem-solving skills, including encoding and transformation for unique representations and dynamic programming, memoization, and backtracking for enumerating all valid segmentations.
Part 1: Unique Morse Code Transformations
Constraints
- `0 <= len(words) <= 1000`
- `0 <= len(words[i]) <= 20`
- Each character in every word is a lowercase English letter from `a` to `z`.
Examples
Input: (['gin', 'zen', 'gig', 'msg'],)
Expected Output: 2
Explanation: `'gin'` and `'zen'` map to the same Morse string, and `'gig'` and `'msg'` map to another one.
Input: (['a'],)
Expected Output: 1
Explanation: A single word always contributes exactly one translation.
Input: ([],)
Expected Output: 0
Explanation: No words means there are no translations.