Code RoomText rewrite rules
EasyPrep Room Coding #4781

Text rewrite rules

CodingAlgorithms & data structuresEntry–Mid~16 min

A documentation build pushes every source line through a chain of text rewrite rules. Each entry of rules is written "find|replace" and splits on its FIRST bar only, so the find text never holds a bar but the replacement may. Run the rules over a line in the order given, each rule finishing the whole line before the next one starts, so a later rule works on what the earlier ones produced. Inside one rule, scan left to right and replace every occurrence, resuming after the text just inserted, so a rule never rewrites its own output. Matching is case sensitive. Skip any rule whose find text is empty, since it would match everywhere. Return the rewritten lines in the order they were given.

Implement
apply_rewrite_chain(lines: list[str], rules: list[str]) → list[str]
Examples
in[["ship TODO by friday"],["TODO|FIXME"]]out["ship FIXME by friday"]
in[["alpha"],["alpha|beta","beta|gamma"]]out["gamma"]
in[["aaaa"],["aa|a"]]out["aa"]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 16 min
InputExpectedGot
[["ship TODO by friday"],["TODO|FIXME"]]["ship FIXME by friday"]not run yetsample
[["alpha"],["alpha|beta","beta|gamma"]]["gamma"]not run yetsample
[["aaaa"],["aa|a"]]["aa"]not run yetsample