A mosaic restorer records the color of every tile in a single row using one lowercase letter per tile, producing a "row code". Before a row is installed, quality control requires that every color used in that row appears exactly as many times as every other color used in that row -- otherwise the row looks visually unbalanced and must be reworked. Given a row code, decide whether it passes this balance check.
A single line containing the row code s, a non-empty string of lowercase English letters.
Print "true" if every distinct letter that appears in s occurs the same number of times as every other distinct letter that appears in s, and "false" otherwise.
Example 1
Input
abacbc
Expected
true
Explanation
The letter counts are a:2, b:2, c:2. Every distinct letter appears exactly twice, so the row is balanced and the answer is true.
Example 2
Input
aaabb
Expected
false
Explanation
The letter counts are a:3, b:2. The two letters do not appear the same number of times, so the answer is false.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →