AO
Back

Stop Word String Processing

Phone ScreenPhone ScreenLast reported October 2025Low Frequency

Problem Overview

Perplexity's stop-word question, from three reports, all posted in October 2025. Two are phone screens (one a video phone screen); the third gives the problem and its streaming follow-up without naming the round. No report gives an outcome. One report says the round comes in several parts and describes two; that poster guesses later parts might add an optimization such as a trie, which no report confirms. No starter code was captured, so every name below is ours.

Given a string and a vocabulary of stop words (one report says a list), return the part of the string before the first stop word. One report says a stop word can appear anywhere.

What the tests call (our setup — ask your interviewer)

def before_first_stop_word(text: str, stop_words: list[str]) -> str: ...   # Part 1
def stream_before_first_stop_word(chunks, stop_words: list[str]): ...      # Part 2, a generator
def collect_stream(chunks, stop_words: list[str]) -> str: ...              # given: joins what your generator yields

stop_words is a list of strings. Our reading of "anywhere": a stop word matches as a substring, even inside a longer word, so stop in abcstopdef gives abc. "First" means the occurrence that starts earliest in the text, whatever the list order. Matching is case-sensitive, and with no stop word in the text the answer is the whole text. These conventions are ours: ask.

Part 1 — text before the first stop word

  • Return the text before the earliest stop-word occurrence: before_first_stop_word(text, stop_words) -> str.
  • One candidate's advice: do not try to optimize this part. The simpler the better, it saves time, but confirm that with the interviewer.

Part 2 — stream the input through a generator

  • The whole string is now too large to take out at once and can only be read piece by piece. Implement stream_before_first_stop_word(chunks, stop_words) as a Python generator over the chunks that yields the text before the first stop word, in as many pieces as you like.
  • chunks is a list or an iterator of strings (our setup). The tests join what you yield with the given collect_stream(chunks, stop_words), and the joined result must equal the Part 1 answer for the joined chunks. They also check that the function returns an iterator, and that it stops reading chunks soon after the stop word has arrived instead of reading the whole input first.
  • Stop words of different lengths can overlap, for example xyz and y arriving as x, y, z. Whether the answer is the text before the earlier-starting word or before the first word to finish arriving is not reported and not graded: ask which one the interviewer wants.
  • The candidate who described this part was not fluent in generator semantics and wrote it slowly; practise yield first.
  • Afterwards, one report says the interviewer asked how to optimize. Not graded; the Debrief has the candidate's answer.

Follow-up Arc

Interviewers escalate through these phases. The order varies, but most candidates see at least one from each bucket.
Trade-off discussion · 2
Trade-off discussion

Now the input is too large to read at once — process it as a stream of chunks with a generator.

Probes for: after Part 1

How would you optimize it?

Probes for: after the streaming version works

What Reports Emphasize

Common mistakes: Optimizing Part 1 before it works: one candidate advises against optimizing it at all (the simpler the better, it saves time) and says to confirm the scope with the interviewer.; Being unfamiliar with Python generator semantics: the candidate who said so wrote the chunked-input Part 2 slowly and suggests practising first.

Interviewer hints: In one round the interviewer asked how to optimize the solution. The candidate's answer, for their own code, used the longest stop word's length, max(stop_word_len), to reduce how much of the string has to be buffered.

What candidates report: One candidate guesses that later parts might optimize the lookup with a trie; no report confirms a third part.

Optimization (our analysis): a stop word that straddles a chunk boundary has at most max_len − 1 characters in the earlier chunk, so keeping that many trailing characters between chunks is enough. Memory is then O(chunk + max_len), whatever the input size. Clarify: whole-word or substring matching, since it changes the scan.

Practice

Write your own against 10 test cases, or read the worked solution — approach, complexity, and code that runs.
Perplexity · Phone Screen · Reported 3× across candidate reports
Is this helpful?