319. Distinct Pieces of Length K
Print how many DISTINCT contiguous pieces of length k the string contains.
Print 0 if k is longer than the string.
abcabc, k = 3 -> 3 (abc, bca, cab, and abc again)
There are four pieces of length 3 and only three distinct ones, because abc
appears twice.
Take every window of length k, put it in a set, and report the size. The
thing to watch is cost: slicing out a fresh string of length k at every one
of n positions is O(n * k) of copying, which the constraints here allow
and which stops being acceptable as k grows.
Constraints - `1 ≤ k ≤ 1000` - `1 ≤ length ≤ 20000` - The string contains lowercase letters only.
Input
The first line contains an integer k.
The second line contains a string of lowercase letters.
Output
Print one integer, the number of distinct pieces of length k.
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.