Class Solution
-
- All Implemented Interfaces:
public final class Solution3298 - Count Substrings That Can Be Rearranged to Contain a String II.
Hard
You are given two strings
word1andword2.A string
xis called valid ifxcan be rearranged to haveword2as a prefix.Return the total number of valid substrings of
word1.Note that the memory limits in this problem are smaller than usual, so you must implement a solution with a linear runtime complexity.
Example 1:
Input: word1 = "bcca", word2 = "abc"
Output: 1
Explanation:
The only valid substring is
"bcca"which can be rearranged to"abcc"having"abc"as a prefix.Example 2:
Input: word1 = "abcabc", word2 = "abc"
Output: 10
Explanation:
All the substrings except substrings of size 1 and size 2 are valid.
Example 3:
Input: word1 = "abcabc", word2 = "aaabc"
Output: 0
Constraints:
<code>1 <= word1.length <= 10<sup>6</sup></code>
<code>1 <= word2.length <= 10<sup>4</sup></code>
word1andword2consist only of lowercase English letters.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final LongvalidSubstringCount(String word1, String word2)-
-
Method Detail
-
validSubstringCount
final Long validSubstringCount(String word1, String word2)
-
-
-
-