Tap here to switch tabs
Problem
Submissions

Problem: Groups of Special-Equivalent Strings

med
30 min
Try to solve the Groups of Special-Equivalent Strings problem.

Statement

You are given an array of strings words where each string has the same length.

A move consists of swapping the characters at index i and index j of a string s such that i(mod2)=j(mod2)i \pmod 2 = j \pmod 2. In other words, you can swap any two characters at even indices or any two characters at odd indices.

Two strings s and t are special equivalent if s can be transformed into t after performing any number of moves.

A group of special equivalent strings is a non-empty subset of words such that every string in the group is special equivalent to every other string in that same group, and no string outside the group is special equivalent to any string in the group.

Return the total number of groups of special equivalent strings in words.

Constraints:

  • 1≤1 \leq words.length ≤1000\leq 1000

  • 1≤1 \leq words[i].length ≤20\leq 20

  • words[i] consists of lowercase English letters.

  • All the strings in words are of the same length.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Groups of Special-Equivalent Strings

med
30 min
Try to solve the Groups of Special-Equivalent Strings problem.

Statement

You are given an array of strings words where each string has the same length.

A move consists of swapping the characters at index i and index j of a string s such that i(mod2)=j(mod2)i \pmod 2 = j \pmod 2. In other words, you can swap any two characters at even indices or any two characters at odd indices.

Two strings s and t are special equivalent if s can be transformed into t after performing any number of moves.

A group of special equivalent strings is a non-empty subset of words such that every string in the group is special equivalent to every other string in that same group, and no string outside the group is special equivalent to any string in the group.

Return the total number of groups of special equivalent strings in words.

Constraints:

  • 1≤1 \leq words.length ≤1000\leq 1000

  • 1≤1 \leq words[i].length ≤20\leq 20

  • words[i] consists of lowercase English letters.

  • All the strings in words are of the same length.