Company: TSMC
Difficulty: medium
Question 3 You are given two strings, s and x. Find the zero-based position where x first appears inside s. String s is made up only of lowercase letters in the range ascii[a-z]. String x is also made up of lowercase letters, but it may contain exactly one wildcard character, *, which stands in for any single character . Function Description Complete the function firstOccurrence in the editor below. It should return an integer giving the zero-based index of the first place x matches inside s, or -1 if no match exists. Parameters: string s : a string of lowercase letters string x : a string of lowercase letters which may contain 1 instance of the wildcard character * Returns: int : the index of the first occurrence, or -1 if x does not occur in s Constraints 1 ≤ length of s ≤ 5 × 10 5 1 ≤ length of x ≤ 1000 Example s = "xabcdey" x = "ab*de" Scanning s from the left, the wildcard-aware match lands at index 1. s x a b c d e y x a b * d e Index 0 1 2 3 4 5 6 Input Format for Custom Testing