Tap here to switch tabs
Problem
Submissions

Problem: Count Substrings Rearrangeable to Contain a String II

med
30 min
Try to solve the Count Substrings That Can Be Rearranged to Contain a String II problem.

Statement

You are given two strings, word1 and word2.

A substring of word1 is considered valid if its characters can be rearranged such that word2 becomes a prefix of the rearranged substring.

Return the total number of valid substrings of word1.

Constraints:

  • 1≤1 \leq word1.length ≤106\leq 10^6

  • 1≤1 \leq word2.length ≤104\leq 10^4

  • word1 and word2 consist only of lowercase English letters.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Count Substrings Rearrangeable to Contain a String II

med
30 min
Try to solve the Count Substrings That Can Be Rearranged to Contain a String II problem.

Statement

You are given two strings, word1 and word2.

A substring of word1 is considered valid if its characters can be rearranged such that word2 becomes a prefix of the rearranged substring.

Return the total number of valid substrings of word1.

Constraints:

  • 1≤1 \leq word1.length ≤106\leq 10^6

  • 1≤1 \leq word2.length ≤104\leq 10^4

  • word1 and word2 consist only of lowercase English letters.