Loading...
Loading...
Loading...
A text analyser counts pieces of a lowercase text that use exactly k different letters. Count the pieces (by position, so equal pieces at different places are counted separately).
Example
Input
abcab 2
Output
4
The pieces ab, bc, ca and ab use exactly two letters. Longer pieces use three.
Try the problem first. Open one hint at a time.
Count the pieces with at most k different letters. Then count the pieces with at most k - 1 different letters.
The difference is the pieces with exactly k.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor