#38Search Query Pattern Analyzer
A search platform records user queries as continuous strings of lowercase characters. The analytics team wants to identify the most frequently repeated short query pattern appearing within the recorded search activity. You are given a string queryStream along with three limits: distinctLimit — the maximum number of different characters allowed in a pattern. shortestPattern — the minimum pattern length to consider. longestPattern — the maximum pattern length to consider.
A pattern is considered valid if: Its length is between shortestPattern and longestPattern & it contains at most distinctLimit different characters. The same pattern may appear at overlapping positions in queryStream. Return the maximum number of occurrences of any valid pattern.
Real-World Applications: Search Trend Detection User Behavior Analysis Query Recommendation Systems
Examples
Example 1
Input: queryStream = "aababcaab"
distinctLimit = 2
shortestPattern = 3
longestPattern = 4
Output: 2
Explanation: The pattern "aab" appears twice and contains only two distinct characters.
Example 2
Input: queryStream = "aaaa"
distinctLimit = 1
shortestPattern = 3
longestPattern = 3
Output: 2
Explanation: The pattern "aaa" occurs twice, including overlapping occurrences.
Example 3
Input: queryStream = "xyxyxy"
distinctLimit = 2
shortestPattern = 2
longestPattern = 4
Output: 3
Explanation: The pattern "xy" occurs three times.
Constraints
- 1 <= queryStream.length <= 100000
- 1 <= distinctLimit <= 26
- 1 <= shortestPattern <= longestPattern
- longestPattern <= 26
- queryStream contains only lowercase English letters.
- A pattern may occur at overlapping positions.
- Only patterns satisfying the distinct-character limit are counted.
