InterviewDB Experience

Blocking Words: Filter Strings Against a Blocklist Using Trie or Set Matching

Interview Experience

Problem

You are given a list of blocked words and a document string.

Return the document with every blocked word replaced by asterisks (*) of equal length. Matching is case-insensitive; non-alpha characters act as word boundaries.

python
def block_words(blocked: list[str], document: str) -> str:
    pass

Example:

blocked  = ["bad", "spam"]
document = "This is a Bad example with spam content."

**output**   -> "This is a ***

**example** with **** content."

Follow-ups
1. How would you handle partial matches, e.g., blocking "bad" should not match "badminton"?
2. If blocked contains 100,000 entries, how do you reduce lookup time? (Trie vs. hash set trade-offs.)
3. The document is a 10 GB log stream arriving in chunks. How do you process it without loading it all in memory?
4. Extend the solution to support wildcard patterns like sp*m.

Full Details

Problem

You are given a list of blocked words and a document string.

Return the document with every blocked word replaced by asterisks (*) of equal length. Matching is case-insensitive; non-alpha characters act as word boundaries.

python
def block_words(blocked: list[str], document: str) -> str:
    pass

Example:

blocked  = ["bad", "spam"]
document = "This is a Bad example with spam content."

**output**   -> "This is a ***

**example** with **** content."

Follow-ups
1. How would you handle partial matches, e.g., blocking "bad" should not match "badminton"?
2. If blocked contains 100,000 entries, how do you reduce lookup time? (Trie vs. hash set trade-offs.)
3. The document is a 10 GB log stream arriving in chunks. How do you process it without loading it all in memory?
4. Extend the solution to support wildcard patterns like sp*m.

About This Question

This is a candidate experience report from a sofi interview during the phone round.

It covers the following topics: Strings, Phone, Trie, Coding, Hash Table .