Skip to content

Practice Groups of Strings

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#2157
LeetCode Problem

Groups of Strings

Problem Statement

Treat each word as its set of lowercase letters; no letter repeats within a word. Two entries connect if one set can become the other by adding one letter, deleting one letter, or replacing one letter, including replacement by itself. Group entries into connected components, including singletons. Return [numberOfGroups,largestGroupSize]; repeated entries count separately in a group size.

Source: Groups of Strings on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
words = ["a","b","ab","cde"]
Output
[2,3]

# Example 2

Input
words = ["a","ab","abc"]
Output
[1,3]

Constraints

1 <= words.length <= 2 * 10^4
1 <= words[i].length <= 26
words[i] consists of lowercase English letters only.
No letter occurs more than once in words[i].

Related LeetCode Problems

Practice more problems similar to Groups of Strings.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.