Back to problems

Perfect Substring

Algorithm · Visa · Medium

You are given a string s made up entirely of digit characters ('0'–'9') and a positive integer k. Count how many contiguous substrings of s meet the following rule: For every digit that actually appears inside the substring, that digit must occur exactly k times. Digits that do not appear in the substring are ignored — they place no restriction on the count. Substrings that start or end at different indices are considered distinct, even if their content looks the same. Input…

Checking your access…