

Actually, brute force can work due to constrains. However, if we count the frequency every time, the time complexity will be O(n**3), which may lead to a TLE.
So a simple way is to memorize the maximum frequency of digits in the substring, the unique digits appear in the substring, and multiple them to see if the length equals end – start + 1.
New knowledge: rolling hash
Rolling hash is a way to turn a string into a unique number. It’s quicker since to compare strings need O(L) time, but to compare numbers we only need O(1) time.