Tap here to switch tabs
Problem
Submissions

Problem: Count Substrings Rearrangeable to Contain a String I

med
30 min
Try to solve the Count Substrings That Can Be Rearranged to Contain a String I 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 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

med
30 min
Try to solve the Count Substrings That Can Be Rearranged to Contain a String I 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 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.