← Uber Interview Insights

Uber·Software Engineer·Onsite - Coding / Algorithms·Intermediate

Intermediate
May 2026

Summary

Uber SWE coding round, got a grid-based word search problem that looked manageable until I realized brute force wasn't going to cut it with 30k words in the input.

Questions Asked (1)

Q1

Given a 2D character grid and a list of words, find all words that can be formed by traversing horizontally or vertically adjacent cells without reusing any cell in a single word's path.

Algorithms & Data Structures
Author's notes

My first instinct was to just DFS from every cell for every word, which works but completely falls apart when you have tens of thousands of words.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a Trie to store the list of words for efficient prefix matching, then perform DFS from each cell in the grid, exploring all four directions while marking cells as visited to avoid reuse. During traversal, check if the current path forms a word in the Trie and add it to the result, pruning branches when no word starts with the current prefix.

Pro tip: Mention that you can optimize by removing words from the Trie once found to avoid duplicate checks, and that early termination when the Trie node has no children can significantly reduce unnecessary exploration.

1. Clarify and Define

Confirm the problem constraints: grid dimensions, word list size, whether words can be reused, and if the output should be unique words. Discuss edge cases like empty grid or empty word list.

2. Choose Data Structures

Select a Trie to store the words for efficient prefix lookup, and use a 2D boolean array or modify the grid in-place to track visited cells during DFS.

3. Design the Algorithm

Outline the DFS approach: for each cell, start a DFS that explores all four directions, checks the Trie for prefixes, and records words when a terminal node is reached. Include backtracking to unmark visited cells.

4. Analyze Complexity

Explain the time complexity: O(M * N * 4^L) in the worst case, where L is the maximum word length, but with Trie pruning it's much faster in practice. Space complexity is O(W * L) for the Trie plus O(L) for recursion stack.

5. Optimize and Discuss Trade-offs

Propose optimizations like removing found words from the Trie, using a HashSet for results to avoid duplicates, and early termination when a Trie node has no children. Discuss alternative approaches like using a HashSet for words if prefix pruning is not needed.

Key Points to Mention

  • Trie data structure for efficient prefix matching and pruning
  • Depth-First Search (DFS) with backtracking to explore all paths
  • Visited cell tracking to avoid reusing cells in a single path
  • Handling of duplicate words and ensuring unique results
  • Time and space complexity analysis with and without optimizations
  • Edge cases: empty grid, empty word list, words longer than grid cells

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