Streaming Keyword Redaction
Updated
Problem statement
Given text and unique case-sensitive keywords, replace every keyword that appears as a complete word with the same number of * characters.
A word is a full run of consecutive ASCII letters, digits, or underscores, ending at any other character or the end of the text. Preserve every non-word character exactly. Substrings inside a larger word are not replaced.
Process the text in one left-to-right pass so the method can be adapted to a very large file.
Function
redactKeywords(text: String, keywords: String[]) → StringExamples
Example 1
text = "red blue redwood"keywords = ["red"]return = "*** blue redwood"The standalone red is replaced, while the prefix inside redwood is preserved.
Example 2
text = "User_1,user_1!"keywords = ["user_1"]return = "User_1,******!"Matching is case-sensitive and underscore is part of a word.
Example 3
text = ""keywords = ["secret"]return = ""Empty text remains empty.
Constraints
0 <= text.length <= 1000000.0 <= keywords.length <= 100000.- Each keyword is a nonempty ASCII word with length at most
100. - The total keyword length is at most
1000000.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Non-Repeating CharacterAutodesk · ONSITE INTERVIEWAutodesk interview questions
- Container Ledger with TradesFlexport · ONSITE INTERVIEWFlexport interview questions
- Count Adjacent Symbol Pairs for BPEAmazon · ONSITE INTERVIEW
- Count a User's Actions in an Event LogMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Map and Accumulate Learning QueriesPalantir · ONSITE INTERVIEWPalantir interview questions
- Filter Pins by Excluded IDsPinterest · ONSITE INTERVIEWPinterest interview questions
- First Non-Repeating CharacterGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
- Minimum Replacements to Make Two Strings AnagramsBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Logger Rate LimiterAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
- Isomorphic StringsRemitly · ONSITE INTERVIEWRemitly interview questions