Hiring process8 levels
  1. 1 IQ Test
  2. 2 Additional Online Test (If Required)
  3. 3 Office Interview with Hiring Manager
  4. 4 Unpaid Test Task (Motivation Check)
  5. 5 Paid Test Task and Follow-Up Interview
  6. 6 Iterative Paid Test Tasks
  7. 7 Office Verification
  8. 8 Final Interview with the Founder

Problems > Ternary Strings Avoiding 00 > Editorial

Ternary Strings Avoiding 00 — Solution & Editorial

Back to the Problem

Build the KMP automaton for the forbidden pattern; states are the length of the current matched prefix. The transfer matrix (rejecting transitions that complete the pattern) raised to the N-th power counts safe strings.

Complexity: O(m3 log N)

Watch out: The automaton must use the KMP failure function so overlapping partial matches transition correctly.