Simon AI receives event names from its product surfaces and needs to locate the first event name matching a partially specified pattern. Given a text string and a pattern containing exactly one ? wildcard, return the lowest index where the pattern matches. The wildcard matches exactly one arbitrary character.
A match must use consecutive characters in text. Return -1 if no match exists.
Implement find_substring(text, pattern):
text is a string.pattern is a non-empty string containing exactly one ?.? must match the corresponding text character exactly.For an efficient solution, avoid checking every complete candidate substring character by character. Use string-search techniques to locate the fixed prefix and suffix around the wildcard.
?? matches exactly one characterdef find_substring(text, pattern):