Count unique Morse-code word transformations
Company: Amazon
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Technical Screen
Overview: 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.
Read the full Amazon Software Engineer interview experience this question came from
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.
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.