A Perfectly Balanced String? Solution | Codeforces Problem Solution 2022
Let's call a string perfectly balanced if for all possible triplets such that is a non-empty substring of and and are characters present in , the difference between the frequencies of and in is not more than .
For example, the strings "aba" and "abc" are perfectly balanced but "abb" is not because for the triplet ("bb",'a','b'), the condition is not satisfied.
You are given a string consisting of lowercase English letters only. Your task is to determine whether is perfectly balanced or not.
A string is called a substring of another string if can be obtained by deleting some characters (possibly ) from the start and some characters (possibly ) from the end of .
The first line of input contains a single integer () denoting the number of testcases.
Each of the next lines contain a single string (), consisting of lowercase English letters.
It is guaranteed that the sum of over all testcases does not exceed .
No comments:
Post a Comment