← Amazon Interview Insights

Amazon·Data Scientist·Online Assessment (OA)·Intermediate

Intermediate
Jun 2026

Summary

Amazon data scientist coding round, two questions back to back. Nothing too wild but the second one had some edge cases that slowed me down.

Questions Asked (2)

Q1

Given an array of words, map each word to its Morse code representation by concatenating the codes for each letter, then return the count of distinct Morse code strings across all words.

Algorithms & Data Structures
Author's notes

Pretty straightforward once you just hardcode the 26-letter mapping and throw everything into a set.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a hash set to store the Morse code representations of each word, then return the size of the set. For each word, map each character to its Morse code using a precomputed dictionary and concatenate the codes.

Pro tip: Mention that the Morse code for each letter is fixed and can be precomputed in a dictionary for O(1) lookup, and that using a set automatically handles duplicates. Also, note that the time complexity is O(N*L) where N is the number of words and L is the average word length, which is optimal.

1. Clarify the problem

Confirm that each letter maps to a unique Morse code string, and that we need to count distinct concatenated strings. Ask if the input array can be empty or contain empty strings.

2. Precompute Morse code mapping

Create a dictionary mapping each lowercase English letter to its Morse code. This allows O(1) lookup per character.

3. Transform each word

For each word, iterate through its characters, look up the Morse code, and concatenate them into a single string. Add this string to a hash set.

4. Count distinct representations

After processing all words, the size of the hash set gives the number of distinct Morse code strings.

5. Analyze complexity

State that the time complexity is O(N*L) where N is the number of words and L is the average length, and space complexity is O(N*L) for the set. This is optimal as we must read all characters.

Key Points to Mention

  • Use a hash set to automatically handle duplicates and count distinct strings.
  • Precompute the Morse code mapping for all 26 letters to avoid repeated lookups.
  • The transformation is straightforward: concatenate codes for each character.
  • Time complexity is O(N*L) and space complexity is O(N*L), which is optimal.
  • Edge cases: empty array returns 0, words with same Morse code are counted once.
  • The problem is essentially about set operations and string manipulation.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

Given a string and a word dictionary, return all possible ways to split the string into a sentence where every word appears in the dictionary. Words can be reused.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This is the one that got me.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem constraints (e.g., dictionary size, string length, expected output size) and then propose a dynamic programming solution that builds sentences from left to right, using memoization to avoid redundant computations. Discuss the time and space complexity, and mention potential optimizations like using a trie for dictionary lookups or pruning branches when no words match.

Pro tip: Emphasize that the number of valid sentences can be exponential, so it's crucial to discuss output-sensitive complexity and consider whether to return all solutions or just count them. Also, mention that in practice, you might use a trie to speed up word lookups, which is a common optimization at Amazon-scale.

1. Clarify requirements and constraints

Ask about input sizes, dictionary size, whether words can be reused, and if the output should be all possible sentences or just a count. Confirm if the dictionary is static or dynamic.

2. Define the recursive structure

Define a function that returns all valid sentences for a substring starting at index i. For each word in the dictionary that matches a prefix of the substring, recursively solve for the remainder and concatenate.

3. Optimize with memoization

Use memoization to cache results for each starting index to avoid recomputing the same subproblems. This reduces time complexity from exponential to polynomial in the number of subproblems times the work per subproblem.

4. Analyze complexity and trade-offs

Discuss time complexity: O(n * m * L) where n is string length, m is dictionary size, and L is average word length, but output size can be exponential. Space complexity includes memoization and output storage.

5. Consider further optimizations

Mention using a trie for dictionary lookups to reduce matching time, or pruning when no words match. Also, discuss iterative DP vs. recursive with memoization.

Key Points to Mention

  • Dynamic programming with memoization to avoid redundant computations
  • Time and space complexity analysis, including output-sensitive complexity
  • Handling of overlapping subproblems and optimal substructure
  • Use of a trie or hash set for efficient word lookups
  • Edge cases: empty string, no valid splits, dictionary with single characters
  • Trade-offs between returning all solutions vs. counting them, and memory implications

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.