Balance strings, by definition, are the strings that contain all the characters of the…
- User
Balance strings, by definition, are the strings that contain all the characters of the alphabet, from a to z, equal no of times. eg- abcdefghijklmnopqrstuvwxyz is a balanced string, aabb is not. Input: First line contains number of test cases T. Each test case contains a string S which made up of only lowercase characters.
Output: For each test case print Yes if the string is balanced string else print No.
Constraints: 1 ≤ T ≤ 10 1 ≤ |S| ≤ 1000
SAMPLE INPUT 2 codemyca abcdefghijklmnopqrstuvwxyz
SAMPLE OUTPUT No Yes
Assistant
pythonimport sys def is_balanced(s): n = len(s) if n % 26 != 0: return False expected = n // 26 freq = [0] * 26 for c in s: idx = ord(c) - ord('a') freq[idx] += 1 for count in freq: if count != expected: return False return True T = int(sys.stdin.readline()) for _ in range(T): s = sys.stdin.readline().strip() print("Yes" if is_balanced(s) else "No")
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.