Setup
Score(i) = sum over j of P[j] * T[i+j] * (P[j] != '?'). Zero score → all non-wildcard positions match.
Advertisement
Correlation via FFT
Correlation = pointwise product of FFTs. Reverse pattern, compute correlation.
Advertisement
Multiple char classes
3 correlations (one per encoding). Combine via magic polynomial identity.
Complexity
O((N+M) log(N+M)) using FFT. Beats naive O(NM) for large N + few queries.