PracHub
QuestionsLearningGuidesInterview Prep

Quick 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.

  • hard
  • Amazon
  • Coding & Algorithms
  • Software Engineer

Count unique Morse-code word transformations

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

Given an array of lowercase strings `words`. Each letter 'a' to 'z' has a corresponding Morse code string (standard 26-letter mapping). A word’s **transformation** is the concatenation of the Morse codes of its letters in order. Return the number of **distinct transformations** among all words. Example: if "cab" transforms to "-.-..--..." ("-.-." + ".-" + "-..."), then two words are considered the same if their full transformed strings are identical.

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.

Given a list of lowercase English words, convert each word into its Morse-code transformation and return how many distinct transformations exist. The Morse mapping is the standard 26-letter mapping in order from 'a' to 'z': ['.-', '-...', '-.-.', '-..', '.', '..-.', '--.', '....', '..', '.---', '-.-', '.-..', '--', '-.', '---', '.--.', '--.-', '.-.', '...', '-', '..-', '...-', '.--', '-..-', '-.--', '--..']. A word's transformation is formed by concatenating the Morse code of each character from left to right. Two words are considered the same if their full transformed strings are identical.

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

  1. Use a fixed array of 26 Morse strings and map each character with its alphabetical index.
  2. Store each transformed word in a set so duplicates are counted only once.
Last updated: May 19, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Compute Edit Distance - Amazon (medium)
  • Minimize Replacements So Equal Product Values Are Contiguous - Amazon (hard)
  • Find a Maximum-Sum Window in a Sparse Array - Amazon (hard)
  • Add One Source to Minimize Grid Inconvenience - Amazon (medium)
  • Implement a Half-Open Interval Range Module - Amazon (hard)