Tap here to switch tabs
Problem
Submissions

Problem: Count Prefix and Suffix Pairs II

Try to solve the Count Prefix and Suffix Pairs II problem.

Statement

You are given an array of strings words.

Let us define a boolean function isPrefixAndSuffix(str1, str2) that returns true if str1 is both a prefix and a suffix of str2, and false otherwise.

Return the total number of index pairs (i, j) such that i<ji < j and isPrefixAndSuffix(words[i], words[j]) is true.

Constraints:

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

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

  • words[i] consists only of lowercase English letters.

  • The sum of the lengths of all words[i] does not exceed 5imes1055 imes 10^5.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Count Prefix and Suffix Pairs II

Try to solve the Count Prefix and Suffix Pairs II problem.

Statement

You are given an array of strings words.

Let us define a boolean function isPrefixAndSuffix(str1, str2) that returns true if str1 is both a prefix and a suffix of str2, and false otherwise.

Return the total number of index pairs (i, j) such that i<ji < j and isPrefixAndSuffix(words[i], words[j]) is true.

Constraints:

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

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

  • words[i] consists only of lowercase English letters.

  • The sum of the lengths of all words[i] does not exceed 5imes1055 imes 10^5.