This question evaluates string manipulation and pattern-matching competency, including substring search, prioritization rules for leftmost and longest matches, and handling of edge cases.
You are given a sentence s (words separated by single spaces) and a list of strings patterns.
For each word in the sentence, if the word contains any pattern as a contiguous substring, wrap the matched substring in square brackets [ and ].
Return the transformed sentence.
s = "hello uber"
,
patterns = ["ll", "ub"]
"he[ll]o [ub]er"
1 <= len(s) <= 10^5
1 <= len(patterns) <= 10^4
<= 10^5
transform(s: string, patterns: list[string]) -> string