Tap here to switch tabs
Problem
Submissions

Problem: Count Substrings Rearrangeable to Contain a String I

Count Substrings Rearrangeable to Contain a String I asks you to count substrings of word1 whose characters can be rearranged so word2 forms the prefix, and return the total number of valid substrings.

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 forms a prefix of the rearranged string.

Return the total count of valid substrings of word1.

Constraints:

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

  • 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 I

Count Substrings Rearrangeable to Contain a String I asks you to count substrings of word1 whose characters can be rearranged so word2 forms the prefix, and return the total number of valid substrings.

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 forms a prefix of the rearranged string.

Return the total count of valid substrings of word1.

Constraints:

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

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

  • word1 and word2 consist only of lowercase English letters.