Pattern Matching Automaton - Problem
Build a deterministic finite automaton (DFA) from a given pattern and simulate it to find all matches in a text string. A DFA is a state machine that processes characters one by one and determines if the current prefix matches the pattern or leads to a potential match.
Given a pattern string pattern and a text string text, return an array of all starting indices where the pattern appears in the text.
The automaton should use the failure function (similar to KMP algorithm) to efficiently handle mismatches by jumping to the appropriate state rather than restarting from the beginning.
Example: If pattern = "aba" and text = "abababa", the pattern appears at indices [0, 2, 4], so return [0, 2, 4].
Input & Output
Constraints
- 1 ≤ pattern.length ≤ 1000
- 1 ≤ text.length ≤ 104
- pattern and text consist of lowercase English letters only