FastPrepWildcard Bad-Word Filter
Problems/Wildcard Bad-Word Filter

Wildcard Bad-Word Filter

Sentry logoSentry● MediumINTERNNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Firsthand Sentry online assessment reports from 2020 through 2023 all describe a bad-word filter that ignores case. It has wildcards for exact, prefix, suffix, and contains matches. The messages have lots of punctuation and repeated spaces, and each match is replaced by the same number of asterisks. Screenshots in the earliest report back up the rules for wildcards at the edges. Our version is about 92% the same as the reported question.

Replace bad words in a message while preserving every punctuation mark and whitespace character.

A candidate word is a maximal run of ASCII letters and digits. Matching ignores case. A pattern without * must equal the whole word. A leading * matches any prefix, a trailing * matches any suffix, and both match any containing word; each wildcard stands for zero or more letters or digits. Only edge wildcards are allowed; patterns containing no letters or digits are ignored.

Replace every letter and digit of a matching word with *.

Function

filterBadWords(badWords: String[], message: String) → String

Examples

Example 1

badWords = ["jerk*","*lame*"]message = "Stop it, you jerkwad! I remain blameless!"return = "Stop it, you *******! I remain *********!"

The prefix and contains patterns match while punctuation remains.

Example 2

badWords = ["bad","*tail","head*"]message = "BAD cocktail headwind badge"return = "*** ******** ******** badge"

Matching ignores case and exact bad does not match badge.

Example 3

badWords = ["*","**"]message = "keep  all!"return = "keep  all!"

Wildcard-only patterns are ignored and repeated spaces stay unchanged.

Example 4

badWords = ["bot*","*404"]message = "Bot42 hit page404, then 404 again; robot2 stayed."return = "***** hit *******, then *** again; robot2 stayed."

Words are runs of letters and digits, so Bot42 matches bot*, and page404 and 404 both match *404, where the wildcard covers zero characters for 404. robot2 does not start with bot.

Constraints

  • 1 <= badWords.length <= 1000.
  • 1 <= message.length <= 100000.
  • Each pattern is either one or more * characters, or ASCII letters and digits with an optional * at either edge.
  • The message contains printable ASCII characters and whitespace (space, tab, newline or carriage return).

More Sentry interview questions

  • Word Wrap with Even JustificationOA · PHONE SCREEN · Seen Dec 2025
  • Find All Word Occurrences in TextPHONE SCREEN · Seen Mar 2023
  • Five-Minute Hit CounterPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2022
  • Minimum Meeting RoomsPHONE SCREEN · Seen Feb 2022

Similar questions at other companies

  • Basic Calculator IITypeSafe AI · OA
  • Find a String Within One Mismatch of AllBarclays · OABarclays interview questions
  • Maximum String OperationsMicrosoft · OAMicrosoft interview questions
  • Perfect SubstringAXQ Capital · OA
  • Reliable LLM Call with Independent Retry BudgetsStripe · OAStripe interview questions
  • Maximum Equal-Bit Pairs in a SubsequenceAmazon · OA
  • Minimum No-Repeat Segments After One Character RemovalSalesforce · OASalesforce interview questions
  • Count Subarrays Matching a Comparison PatternTikTok · OATikTok interview questions
  • Earliest Time to Schedule a MeetingMathWorks · OAMathWorks interview questions
  • Earliest Meeting Start on a 24-Hour ClockIMC Trading · OAIMC Trading interview questions

Interview reports that mention this question

  • Sentry Software Engineer Interview Questions: 18 Experiences
  • Sentry SWE Intern OA and Technical Interview: 16 Experiences
  • Sentry SWE New Grad OA and Technical Screen: 12 Experiences

Sentry interview experiences

  • Sentry Experienced First Technical Interview: 8 Experiences
  • Sentry SWE Intern First Technical Interview: 10 Experiences
  • Sentry SWE New Grad First Technical Interview: 4 Experiences
All Sentry interview questionsSee Sentry hiring insights
Saved
class Solution {
    public String filterBadWords(String[] badWords, String message) {
        // write your code here
    }
}
Checking account…