#1897
Easy Algorithms Redistribute characters to make all strings equal
Hash Table String Counting
66.8% acceptance
Feb 25, 2026
1162
85
Given an array of strings words, in one operation you can move any character from words[i] to words[j]. Return true if you can make every string equal using any number of operations.
Solution
Rust
Time O(n²)
Space O(1)
impl Solution {
pub fn make_equal(words: Vec<String>) -> bool {
let n = words.len();
let mut freq = [0usize; 26];
for w in &words {
for b in w.bytes() {
freq[(b - b'a') as usize] += 1;
}
}
freq.iter().all(|&c| c % n == 0)
}
}