893. Groups of Special-Equivalent Strings Medium

@problem@discussion
#Array#Hash Table#String



1/**
2 * [893] Groups of Special-Equivalent Strings
3 *
4 * You are given an array of strings of the same length words.
5 * In one move, you can swap any two even indexed characters or any two odd indexed characters of a string words[i].
6 * Two strings words[i] and words[j] are special-equivalent if after any number of moves, words[i] == words[j].
7 * 
8 * 	For example, words[i] = "zzxy" and words[j] = "xyzz" are special-equivalent because we may make the moves "zzxy" -> "xzzy" -> "xyzz".
9 * 
10 * A group of special-equivalent strings from words is a non-empty subset of words such that:
11 * 
12 * 	Every pair of strings in the group are special equivalent, and
13 * 	The group is the largest size possible (i.e., there is not a string words[i] not in the group such that words[i] is special-equivalent to every string in the group).
14 * 
15 * Return the number of groups of special-equivalent strings from words.
16 *  
17 * Example 1:
18 * 
19 * Input: words = ["abcd","cdab","cbad","xyzz","zzxy","zzyx"]
20 * Output: 3
21 * Explanation: 
22 * One group is ["abcd", "cdab", "cbad"], since they are all pairwise special equivalent, and none of the other strings is all pairwise special equivalent to these.
23 * The other two groups are ["xyzz", "zzxy"] and ["zzyx"].
24 * Note that in particular, "zzxy" is not special equivalent to "zzyx".
25 * 
26 * Example 2:
27 * 
28 * Input: words = ["abc","acb","bac","bca","cab","cba"]
29 * Output: 3
30 * 
31 *  
32 * Constraints:
33 * 
34 * 	1 <= words.length <= 1000
35 * 	1 <= words[i].length <= 20
36 * 	words[i] consist of lowercase English letters.
37 * 	All the strings are of the same length.
38 * 
39 */
40pub struct Solution {}
41
42// problem: https://leetcode.com/problems/groups-of-special-equivalent-strings/
43// discuss: https://leetcode.com/problems/groups-of-special-equivalent-strings/discuss/?currentPage=1&orderBy=most_votes&query=
44
45// submission codes start here
46
47impl Solution {
48    pub fn num_special_equiv_groups(words: Vec<String>) -> i32 {
49        0
50    }
51}
52
53// submission codes end
54
55#[cfg(test)]
56mod tests {
57    use super::*;
58
59    #[test]
60    fn test_893() {
61    }
62}
63


Back
© 2025 bowen.ge All Rights Reserved.