text and kit. Treat kit as a set of letters, repeats included. A substring of text qualifies if it holds the whole set: every letter appears in it at least as many times as in kit. Put differently, its letters can be rearranged so that it starts with kit.
Count the non-empty substrings of text that qualify. Substrings at different positions count separately.text='cabd', kit='ab' → 4
A substring needs at least one "a" and one "b". These are "ab", "cab", "abd" and "cabd".
text='abab', kit='aaa' → 0
The whole string has only two a's while three are needed, so the answer is 0.
text='zzz', kit='z' → 6
text='cabd', kit='ab'
4
Run checks the first 3 tests in your browser. Submit checks all 107 tests on the server, hidden ones included.