Katkat

Solve Two String Problems

AmazonData Engineer · Technical Screen

Last updated

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.

You are asked to solve the following two coding problems:

  1. Unique Morse Code Transformations

You are given an array of lowercase English words, words. Each letter 'a' through 'z' maps to its standard Morse code representation. The translation of a word is formed by concatenating the Morse code of each of its letters in order.

For example, the word "cab" translates to "-.-..--..." because:

  • c -> -.-.
  • a -> .-
  • b -> -...

Return the number of distinct word translations among all words in the array.

  1. Word Break II

You are given a string s and a dictionary of valid words, wordDict. Insert spaces into s to form all possible sentences such that every segmented word appears in wordDict.

Return all possible valid sentences in any order.

Notes:

  • A dictionary word may be reused multiple times.
  • If multiple segmentations are possible, return all of them.