Redistribute Characters to Make All Strings Equal

easy string counting

Problem

You are given an array of strings words. In one operation you may move any character from any string to any position in any string. Return true if you can make every string equal after some number of operations, otherwise false.

Inputwords = ["abc", "aabc", "bc"]
Outputtrue
Totals a:3, b:3, c:3; with 3 words each becomes "abc".

def make_equal(words):
    n = len(words)
    count = [0] * 26
    for w in words:
        for ch in w:
            count[ord(ch) - ord("a")] += 1
    return all(c % n == 0 for c in count)
function makeEqual(words) {
  const n = words.length;
  const count = new Array(26).fill(0);
  for (const w of words) {
    for (const ch of w) {
      count[ch.charCodeAt(0) - 97]++;
    }
  }
  return count.every(c => c % n === 0);
}
class Solution {
    public boolean makeEqual(String[] words) {
        int n = words.length;
        int[] count = new int[26];
        for (String w : words)
            for (char ch : w.toCharArray())
                count[ch - 'a']++;
        for (int c : count)
            if (c % n != 0) return false;
        return true;
    }
}
bool makeEqual(vector<string>& words) {
    int n = words.size();
    vector<int> count(26, 0);
    for (auto& w : words)
        for (char ch : w)
            count[ch - 'a']++;
    for (int c : count)
        if (c % n != 0) return false;
    return true;
}
Time: O(total characters) Space: O(1)