Tap here to switch tabs
Problem
Submissions

Problem: Count Pairs of Equal Substrings With Minimum Difference

Count Pairs of Equal Substrings With Minimum Difference asks you to count matching substring pairs from two strings whose first ending index minus second starting index is as small as possible.

Statement

You are given two 00 indexed strings, firstString and secondString, each consisting of lowercase English letters.

You need to find the number of index quadruples (i,j,a,b)(i, j, a, b) that satisfy the following conditions:

  • 0≤i≤j<0 \leq i \leq j < firstString.length

  • 0≤a≤b<0 \leq a \leq b < secondString.length

  • The substring of firstString from index ii to jj is identical to the substring of secondString from index aa to bb

  • The value of j−aj - a is minimized among all valid quadruples

Return the number of quadruples that achieve this minimum value of j−aj - a.

Constraints:

  • 1≤1 \leq firstString.length, secondString.length ≤2imes105\leq 2 imes 10^5

  • Both firstString and secondString consist only of lowercase English letters.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Count Pairs of Equal Substrings With Minimum Difference

Count Pairs of Equal Substrings With Minimum Difference asks you to count matching substring pairs from two strings whose first ending index minus second starting index is as small as possible.

Statement

You are given two 00 indexed strings, firstString and secondString, each consisting of lowercase English letters.

You need to find the number of index quadruples (i,j,a,b)(i, j, a, b) that satisfy the following conditions:

  • 0≤i≤j<0 \leq i \leq j < firstString.length

  • 0≤a≤b<0 \leq a \leq b < secondString.length

  • The substring of firstString from index ii to jj is identical to the substring of secondString from index aa to bb

  • The value of j−aj - a is minimized among all valid quadruples

Return the number of quadruples that achieve this minimum value of j−aj - a.

Constraints:

  • 1≤1 \leq firstString.length, secondString.length ≤2imes105\leq 2 imes 10^5

  • Both firstString and secondString consist only of lowercase English letters.