#1897

Redistribute Characters to Make All Strings Equal

pupil · 320 · lc easy +21 · verified · 66.8% accepted · 1,162 likes · top 72%

Description

You are given an array of strings words. In one operation, move any character from one string to any position in another string.

Return true if you can make every string in words equal by performing any number of such operations, or false otherwise.

Example 1:

Input: words = ["abc","aabc","bc"]
Output: true
Explanation: Move the first 'a' in words[1] to the front of words[2],
to make words[1] = "abc" and words[2] = "abc".
All the strings are now equal to "abc", so return true.

Example 2:

Input: words = ["ab","a"]
Output: false
Explanation: It is impossible to make all the strings equal using the operation.

Code

1
2
3