You are given an array a of strings.
Two strings S and T are special-equivalent if after any number of moves, S = T.
A move consists of choosing two indices I and j With I % 2 = J % 2, and swapping s [I] With s [J].
Now, a group of special-equivalent strings from a is a non-empty subset s of a such that any string not in S is not special-equivalent with any string in S.
Return the number of groups of special-equivalent strings from.
Example 1:
Input: ["A", "B", "C", "A", "C", "C"]
Output: 3
Explanation: 3 groups ["A", "a"], ["B"], ["C", "C", "C"]
Example 2:
Input: ["AA", "BB", "AB", "ba"]
Output: 4
Explanation: 4 groups ["AA"], ["BB"], ["AB"], ["ba"]
Example 3:
Input: ["ABC", "ACB", "BAC", "BCA", "cab", "CBA"]
Output: 3
Explanation: 3 groups ["ABC", "CBA"], ["ACB", "BCA"], ["BAC", "cab"]
Example 4:
Input: ["ABCD", "cdab", "adcb", "cbad"]
Output: 1
Explanation: 1 group ["ABCD", "cdab", "adcb", "cbad"]
Note:
- 1 <= A. Length <= 1000
- 1 <= A [I]. Length <= 20
- All a [I] have the same length.
- All a [I] consist of only lowercase letters.
Class solution: def numspecialequivgroups (self, A): "": Type A: List [STR]: Rtype: int "s = set () for t in: even = ''odd ='' for I in range (LEN (t): If I % 2 = 0: Even + = T [I] else: odd + = T [I] S. add (''. join (sorted (even) + ''. join (sorted (ODD) return Len (s)
893. Groups of special-equivalent strings