You're given an array of pattern strings and a target word. Your task is to count how many of these patterns actually appear as substrings within the target word.
A substring is a contiguous sequence of characters within a string. For example, "cat" is a substring of "concatenate", but "cta" is not (since the characters aren't contiguous).
Goal: Return the total count of pattern strings that exist as substrings in the target word.
Input: An array of strings patterns and a string word
Output: An integer representing the count of matching patterns
Input & Output
Visualization
Time & Space Complexity
Where n is the number of patterns and m is the length of the word. Built-in methods are optimized and average much better than brute force.
Only using a counter variable, no additional data structures needed
Constraints
- 1 โค patterns.length โค 100
- 1 โค patterns[i].length โค 100
- 1 โค word.length โค 100
- patterns[i] and word consist of lowercase English letters only