Ask AI
Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.
Open Claude Desktopstrings · aho-corasick
The organizer’s problem statement is available at the official source link.
sample trace
Censoring: remove any matching pattern
The sample has two forbidden words. An automaton tracks all pattern prefixes while characters are appended; when one completes at the stack suffix, remove it and restore the previous match state.
input
begintheescapexecutionatthebreakofdawnpatterns
escapeexecution
removed In Order
escapeexecution
output
beginthatthebreakofdawntrace
begintheescapexecutionatthebreakofdawnbegintheexecutionatthebreakofdawnbeginthatthebreakofdawn
- 1
Build multi-pattern matcher
Insert escape and execution into a trie and add failure links so suffix matches are found in one pass. - 2
Append and match
Scan the input into an output stack while tracking the automaton state for each stack prefix. - 3
Pop completed words
Remove a completed forbidden suffix immediately; the sample removes escape, then execution. - 4
Finish
The remaining text is beginthatthebreakofdawn, matching the published output.
Tools
1
2
3
4
5
6
7
8
9
10
11
12
Draft saved locally
|12 lines, 156 charsRun output
Run your code to see output.