Check if frequencies can be equal
Easy Accuracy: 30.49% Submissions: 23235 Points: 2

Given a string s which contains lower alphabetic characters, the task is to check if its possible to remove at most one character from this string in such a way that frequency of each distinct character becomes same in the string.
 

 

Input:
The first line of input contains an integer T denoting the no of test cases. Then T test cases follow. Each test case contains a string s.

Output:
For each test case in a new line print 1 if its possible to make frequencies of all characters equal else print 0.

Constraints:
1 <= T <= 1000
1 <= length of strings <= 10000

Example:
Input:

2
xyyz
xxxxyyzz

Output:
1
0

Explanation:
Testcase 2:
It is not possible to make frequency of each character same just by removing at most one character from above string.

 

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.