Leetcode 929 Solution

This article provides solution to leetcode question 929 (groups-of-special-equivalent-strings)

https://leetcode.com/problems/groups-of-special-equivalent-strings

Solution

class Solution:
    def numSpecialEquivGroups(self, A: List[str]) -> int:
        m = set()

        for word in A:
            s1 = []
            s2 = []
            for i, ch in enumerate(word):
                if i % 2 == 0:
                    s1.append(ch)
                else:
                    s2.append(ch)
            s1.sort()
            s2.sort()

            key = ("".join(s1), "".join(s2))
            m.add(key)

        return len(m)