Count Matching Pattern Entries. For each string in patterns, check whether it occurs contiguously inside word. Return the number of matching array entries. Repeated pattern entries count independently, but one entry contributes at most one regardless of its number of occurrences.
### Problem
Return how many array entries in `patterns` occur as contiguous substrings of `word`. Repeated entries in the array count separately. An individual entry contributes one when it occurs at least once, regardless of how many matching positions it has.
```cpp
class Solution {
public:
int numOfStrings(vector<string>& patterns, string word);
};
```
### Examples
**Example 1:**
```text
patterns = ["an","na","x","an"], word = "banana"
Output: 3
Explanation: Both entries "an" and the entry "na" match; "x" does not.
```
**Example 2:**
```text
patterns = ["cat","at","tac"], word = "cat"
Output: 2
Explanation: The whole word and its suffix "at" match.
```
### Constraints
- `1 <= patterns.length <= 100`.
- Pattern lengths and word length lie in `[1,100]`.
- All characters are lowercase English letters.
### Clarifying Questions
This tests substring existence, not subsequence membership or number of occurrences.
```hint Inspect the structure
What should happen when two array entries have identical text?
```
### Reasoning checkpoints
- Count pattern entries rather than matching locations, retaining the multiplicity of repeated array entries.
- Apply contiguous substring matching, including whole-word matches and patterns longer than the word.
### Optional extensions
How could you answer many large batches against the same unchanged word more efficiently?
Overview: Count Matching Pattern Entries. For each string in patterns, check whether it occurs contiguously inside word. Return the number of matching array entries. Repeated pattern entries count independently, but one entry contributes at most one regardless of its number of occurrences.
Return how many array entries in patterns occur as contiguous substrings of word. Repeated entries in the array count separately. An individual entry contributes one when it occurs at least once, regardless of how many matching positions it has.
class Solution {
public:
int numOfStrings(vector<string>& patterns, string word);
};
Examples
Example 1:
patterns = ["an","na","x","an"], word = "banana"
Output: 3
Explanation: Both entries "an" and the entry "na" match; "x" does not.
Example 2:
patterns = ["cat","at","tac"], word = "cat"
Output: 2
Explanation: The whole word and its suffix "at" match.
Constraints
1 <= patterns.length <= 100
.
Pattern lengths and word length lie in
[1,100]
.
All characters are lowercase English letters.
Clarifying Questions Guidance
This tests substring existence, not subsequence membership or number of occurrences.
Reasoning checkpoints
Count pattern entries rather than matching locations, retaining the multiplicity of repeated array entries.
Apply contiguous substring matching, including whole-word matches and patterns longer than the word.
Optional extensions
How could you answer many large batches against the same unchanged word more efficiently?