#3298

Count Substrings That Can Be Rearranged to Contain a String II

expert · 1280 · lc hard +32 · 56.1% accepted · 89 likes · top 50%

Description

You are given strings word1 and word2. A string is valid if its characters can be rearranged so word2 is a prefix. Return the total count 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.

Code

1
2
3