Company: Microsoft_12july
Difficulty: medium
Perfect Substring Problem Description You are given a string s made up only of the digits 0 to 9 , and an integer k . A substring of s is any non-empty block of consecutive characters of s . A substring is called perfect if every distinct digit that appears anywhere in that substring appears exactly k times inside it . Digits that do not appear in the substring at all are ignored. Count how many perfect substrings s contains. Two perfect substrings that consist of the same characters but start at different positions are counted separately — you are counting occurrences (start/end position pairs), not distinct strings. (inferred — the source does not say this in words, but Example 1 lists the two separate occurrences of 22 at positions 7-8 and 8-9 as two of its six answers, so occurrences are what is being counted.) The empty substring is never counted. (inferred — the source never mentions it; it would satisfy the condition vacuously at every position, which would mak