Clarify the requirements and edge cases first, then propose an efficient algorithm using tokenization and a hash set for O(1) tag lookups. Discuss trade-offs between preprocessing (e.g., tokenizing sentences once) and on-the-fly checking, and analyze time/space complexity.
Pro tip: Mention that you'd use a regex with word boundaries (\b) to ensure whole-word matching, but also consider Unicode and punctuation handling. Show awareness of performance by suggesting early termination once a tag is found in a sentence.
Ask about input size, definition of 'whole word' (e.g., punctuation, hyphens, Unicode), and whether tags can overlap. Confirm case-insensitivity and that a sentence counts if any tag matches.
Use a hash set for tags to enable O(1) membership checks. Tokenize each sentence into words, stripping punctuation, and compare each token against the set.
Iterate through sentences; for each, tokenize and check each token against the tag set. If a match is found, increment the count and break early to avoid unnecessary checks.
Consider empty sentences, empty tag list, tags with special characters, and case variations. Ensure tokenization correctly handles punctuation and Unicode word boundaries.
Time: O(S * W) where S is number of sentences and W is average words per sentence, assuming O(1) set lookups. Space: O(T) for the tag set, where T is number of tags.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.