
Redistribute Characters to Make All Strings Equal (easy)
Problem Statement
Given an array of strings words, return true if you can make all strings equal in words array by performing any number of swap operations. Otherwise, return false.
In one swap operation, you can pick any two indices i and j, and move any characters from words[i] to any position of the words[j].
Examples
-
Example 1:
- Input: words =
["aaa","bbb","ccc", "abc"] - Expected Output:
true - Justification: Each string has 3 characters of a single type, and the last string has all 3 characters. We can redistribute the characters to form a string like "abc" making the distribution equal.
- Input: words =
-
Example 2:
- Input: words =
["ab","bc","cd","de","ea"] - Expected Output:
false - Justification: The characters cannot be redistributed to make all strings equal because all characters appear only twice, making equal distribution impossible.
- Input: words =
-
Example 3:
- Input: words =
["zzx","xzz","zxz"] - Expected Output:
true - Justification: We can redistribute characters to have each string contain one "x" and two "z"s, like "zzx", "xzz", "zxz", maintaining equal distribution.
- Input: words =
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Unlock this and all other premium problems.
No code editor for this lesson
This lesson focuses on concepts and theory