Problem statement:
Given an array of strings (terms) and a target string, find the number of occurrences of each term in the target. You only need to implement the Count method.
Parameters / Requirements:
- You may use any data structures you create.
- The returned map/list must follow the same order as the terms array (e.g.,“fizz”first,“buzz”second,“fizzbuzz”third).
- Assume the terms array has been de-duplicated.
- Do not use any regular expression APIs/libraries.
- Blank strings (“”) and null input should be handled; return zeros for all terms.
- No exceptions need to be thrown/handled.
- Example test strings include:
- “fizz buzz fizzbuzz”→ {fizz=2, buzz=2, fizzbuzz=1}
- “fizzfizz fizz buzz fizzbuzz”→ {fizz=4, buzz=1, fizzbuzz=0}
- more mixed cases as provided.
Without regex, implement multi-pattern counting. Options: naive sliding checks with indexing by first letter/length, or Aho–Corasick for optimal performance. Count overlapping matches unless specified otherwise. Preserve the order of terms in the output; handle empty/null input by returning zeros.
The VOprep team has long accompanied candidates through various major company OAs and VOs, including Oracle, Google, Amazon, Citadel, SIG, providing real-time voice assistance, remote practice, and interview pacing reminders to help you stay smooth during critical moments. If you are preparing for these companies, you can check out our customized support plans—from coding interviews to system design, we offer full guidance to help you succeed.