Start by clarifying the requirements and edge cases, then outline a solution using a hash map to store word-to-sentence-index lists. Emphasize normalization (lowercasing, punctuation stripping) and discuss time complexity in terms of total words processed.
Pro tip: Mention that you would use a defaultdict(list) to avoid key errors and that sorting can be done once at the end or maintained during insertion if indices are processed in order. Also, discuss trade-offs between preprocessing all sentences versus lazy processing.
Ask about punctuation handling (e.g., hyphens, apostrophes), case sensitivity, and whether sentence indices are 0-based or 1-based. Confirm that words are whitespace-separated tokens after stripping punctuation.
Use a hash map (dictionary) where keys are normalized words and values are lists of sentence indices. Consider using a defaultdict(list) for efficient insertion.
Iterate through the mapping, for each sentence, normalize the text (lowercase, remove punctuation), split into words, and for each word, append the sentence index to the list in the hash map.
After processing all sentences, sort each list of indices (if not already sorted) and return the mapping. If sentences are processed in increasing index order, lists will be naturally sorted, avoiding extra sorting.
State that the time complexity is O(N + M log M) where N is total number of words across all sentences and M is the average number of occurrences per word (for sorting). If indices are processed in order, sorting is not needed, making it O(N).
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.