Check if All Characters Have Equal Number of Occurrences

Given a string s, return true if s is a good string, or false otherwise.

A string s is good if all the characters that appear in s have the same number of occurrences (i.e., the same frequency).

Example 1
Inputs = "abacbc"
Outputtrue
The characters that appear in s are 'a', 'b', and 'c', and all characters occur 2 times in s.
Example 2
Inputs = "aaabb"
Outputfalse
The characters that appear in s are 'a' and 'b'; 'a' occurs 3 times while 'b' occurs 2 times, which is not the same number of times.

Constraints

  • 1 <= s.length <= 1000
  • s consists of lowercase English letters.

Asked at 4 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate