Count unique Morse-code word transformations
Company: Amazon
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Technical Screen
Quick Answer: This question evaluates a candidate's ability to implement string transformations based on a fixed character-to-code mapping and to identify distinct results, testing competencies in encoding, string manipulation, and deduplication.
Constraints
- 0 <= len(words) <= 1000
- 1 <= len(word) <= 20
- Each word contains only lowercase English letters 'a' to 'z'
Examples
Input: ["gin", "zen", "gig", "msg"]
Expected Output: 2
Explanation: The words 'gin' and 'zen' share one transformation, and 'gig' and 'msg' share another, so there are 2 distinct transformations.
Input: ["a"]
Expected Output: 1
Explanation: There is only one word, so there is exactly one transformation.
Input: []
Expected Output: 0
Explanation: With no words, there are no transformations.
Input: ["cab", "abc", "bac", "cab"]
Expected Output: 3
Explanation: The duplicate 'cab' does not increase the count. The transformations of 'cab', 'abc', and 'bac' are all different, so the answer is 3.
Hints
- Use a fixed array of 26 Morse strings and map each character with its alphabetical index.
- Store each transformed word in a set so duplicates are counted only once.