Tap here to switch tabs
Problem
Submissions

Problem: Count Valid Word Occurrences

Try to solve the Count Valid Word Occurrences problem.

Statement

You are given an array of strings chunks and an array of strings queries.

First, concatenate all strings in chunks in order to form a single text string s.

The string s is divided into words according to the following rules:

  • Words consist of lowercase English letters and joiner hyphens '-'.

  • A hyphen '-' is considered a joiner hyphen if and only if it is immediately preceded and immediately followed by a lowercase English letter.

  • Any character that is not part of a valid word (such as spaces and non joiner hyphens) serves as a separator.

  • Consecutive separators are treated as a single delimiter.

For each query in queries, determine how many times queries[i] appears as an exact full word in s.

Return an integer array where the ii-th element is the frequency of queries[i] in s.

Constraints:

  • 1≤1 \leq chunks.length ≤105\leq 10^5

  • 1≤1 \leq chunks[i].length ≤105\leq 10^5

  • The total length of all strings in chunks does not exceed 10510^5.

  • chunks[i] consists only of lowercase English letters, spaces, and '-'.

  • 1≤1 \leq queries.length ≤105\leq 10^5

  • 1≤1 \leq queries[i].length ≤105\leq 10^5

  • The total length of all strings in queries does not exceed 10510^5.

  • queries[i] consists only of lowercase English letters and '-'.

  • queries[i] is a valid word: it does not start or end with '-', and it does not contain 22 consecutive hyphens.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Count Valid Word Occurrences

Try to solve the Count Valid Word Occurrences problem.

Statement

You are given an array of strings chunks and an array of strings queries.

First, concatenate all strings in chunks in order to form a single text string s.

The string s is divided into words according to the following rules:

  • Words consist of lowercase English letters and joiner hyphens '-'.

  • A hyphen '-' is considered a joiner hyphen if and only if it is immediately preceded and immediately followed by a lowercase English letter.

  • Any character that is not part of a valid word (such as spaces and non joiner hyphens) serves as a separator.

  • Consecutive separators are treated as a single delimiter.

For each query in queries, determine how many times queries[i] appears as an exact full word in s.

Return an integer array where the ii-th element is the frequency of queries[i] in s.

Constraints:

  • 1≤1 \leq chunks.length ≤105\leq 10^5

  • 1≤1 \leq chunks[i].length ≤105\leq 10^5

  • The total length of all strings in chunks does not exceed 10510^5.

  • chunks[i] consists only of lowercase English letters, spaces, and '-'.

  • 1≤1 \leq queries.length ≤105\leq 10^5

  • 1≤1 \leq queries[i].length ≤105\leq 10^5

  • The total length of all strings in queries does not exceed 10510^5.

  • queries[i] consists only of lowercase English letters and '-'.

  • queries[i] is a valid word: it does not start or end with '-', and it does not contain 22 consecutive hyphens.