← Walmart Interview Insights

Walmart·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Coding screen for a software engineer role, one question about building an inverted index from a sentence map. Pretty straightforward on the surface but they wanted complexity analysis too, which I wasn't fully prepared to articulate cleanly.

Questions Asked (1)

Q1

Given a mapping from sentence index to sentence text, build an inverted index: a mapping from each word to the sorted list of sentence indices where that word appears. Matching should be case-insensitive, treat whitespace-separated tokens as words, and strip punctuation. Also discuss the time complexity.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I got the basic logic down pretty fast.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the requirements and edge cases, then outline a step-by-step algorithm: iterate through sentences, tokenize each sentence by splitting on whitespace, normalize tokens by lowercasing and stripping punctuation, and insert sentence indices into a hash map where each word maps to a list. After processing all sentences, sort each list (or maintain sorted order during insertion) and analyze time complexity as O(N + W log W) where N is total tokens and W is total unique word occurrences.

Pro tip: Mention that you can avoid sorting by processing sentences in order and appending indices, which naturally keeps lists sorted, reducing complexity to O(N). This shows attention to efficiency and practical optimization.

1. Clarify requirements and edge cases

Ask about punctuation handling (e.g., hyphens, apostrophes), case sensitivity, and whether to include empty tokens. Confirm that sentence indices are 0-based or 1-based.

2. Design the data structure

Use a hash map (dictionary) where keys are normalized words and values are lists of sentence indices. Consider using a set to avoid duplicates if a word appears multiple times in the same sentence, but clarify if duplicates are needed.

3. Implement tokenization and normalization

For each sentence, split on whitespace, convert to lowercase, and strip punctuation using a regex or string translation. Skip empty tokens.

4. Build and sort the index

Iterate through sentences in order, and for each token, append the sentence index to the word's list. Since sentences are processed in order, lists remain sorted; otherwise, sort each list at the end.

5. Analyze time and space complexity

Time: O(N + U log U) if sorting, or O(N) if appending in order, where N is total tokens and U is total unique word occurrences. Space: O(N) for the index.

Key Points to Mention

  • Case-insensitive matching: convert all tokens to lowercase before indexing.
  • Punctuation stripping: use regex or string.punctuation to remove punctuation from tokens.
  • Whitespace-separated tokens: split on whitespace (e.g., using split() which handles multiple spaces).
  • Sorted lists: either sort each list after building or maintain sorted order by processing sentences sequentially.
  • Time complexity: O(N) if appending in order, O(N + U log U) if sorting; space O(N).
  • Edge cases: empty sentences, words with apostrophes (e.g., 'don't'), and duplicate words in the same sentence.

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