# 30.12.2023 [1897. Redistribute Characters to Make All Strings Equal]
Is it possible to split all the words[] characters into words.size groups
30.12.2023
1897. Redistribute Characters to Make All Strings Equal easy
blog post
youtube
Join me on Telegram
https://t.me/leetcode_daily_unstoppable/455
Problem TLDR
Is it possible to split all the words[] characters into equal words.size strings.
Intuition
To understand the problem, consider example: a abc abbcc
-> [abc] [abc] [abc]
. We know the result words count, and we know the count of each kind of character. So, just make sure, every character’s count can be separated into words.size
groups.
Approach
to better understand the problem, consider adding more examples
there can be more than one repeating character in group,
[aabc] [aabc] [aabc]
Complexity
Time complexity:
O(nw)Space complexity:
O(1)
Code
fun makeEqual(words: Array<String>) =
IntArray(26).apply {
for (w in words) for (c in w) this[c.toInt() - 'a'.toInt()]++
}.all { it % words.size == 0 }