← Uber Interview Insights

Uber·Machine Learning Engineer·Technical Phone Screen·Senior

Senior
May 2026

Summary

Uber ML engineer round, one coding question the whole time. It was a text generation problem that looked straightforward but had enough edge cases to keep you honest.

Questions Asked (1)

Q1

Build a two-part text generation system: first, write a function that takes a text corpus and builds a frequency map tracking which words follow each word and how often. Second, write a generator that uses that map to produce a sequence of a given length by always picking the highest-frequency next word from the current one.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The frequency map part was fine, tokenize on whitespace, strip punctuation, nested dict.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem requirements and edge cases, then outline a two-step solution: first, build a frequency map using a dictionary of dictionaries, and second, generate text by always selecting the highest-frequency next word. Discuss trade-offs such as tie-breaking strategies, handling unknown words, and potential optimizations for large corpora.

Pro tip: Mention that for production systems, you'd likely use a more sophisticated model like an n-gram or neural language model, but this simple approach demonstrates core concepts. Also, proactively discuss how to handle ties (e.g., random selection among top words) and out-of-vocabulary words to show thoroughness.

1. Clarify Requirements and Edge Cases

Ask about corpus size, tokenization rules, handling punctuation/case, and what to do when no next word exists or when there are ties. Confirm the output format and whether the generator should start from a given word or a random word.

2. Design the Frequency Map

Propose using a dictionary where each key is a word and the value is another dictionary mapping next words to their counts. Discuss tokenization (e.g., splitting on whitespace, lowercasing) and how to update counts efficiently.

3. Implement the Generator

Explain that the generator will start with a seed word (or random word), then repeatedly look up the current word in the map, select the next word with the highest count, and append it. Continue until the desired length is reached or no next word exists.

4. Address Edge Cases and Trade-offs

Discuss tie-breaking (e.g., random choice among top words), handling unknown words (e.g., stop or pick random), and memory/time complexity. Mention that this greedy approach may lead to repetitive or nonsensical text, and suggest alternatives like probabilistic sampling.

5. Test and Validate

Walk through a small example to verify correctness, and mention unit tests for edge cases like empty corpus, single word, and ties. Optionally, discuss how to extend to n-grams for better context.

Key Points to Mention

  • Use a nested dictionary (defaultdict) for the frequency map to efficiently track next-word counts.
  • Tokenization strategy: split on whitespace, handle punctuation, and consider case normalization.
  • Tie-breaking: when multiple next words have the same highest frequency, choose randomly or deterministically (e.g., alphabetical).
  • Handling out-of-vocabulary or end-of-sequence: define behavior when no next word exists (e.g., stop generation or pick a random word).
  • Time and space complexity: O(N) to build the map, O(L) to generate L words, with memory proportional to unique word pairs.
  • Limitations of greedy selection: may produce repetitive text; mention probabilistic sampling or n-grams as improvements.

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