Problem: Secret Passwords Task: Strings are equivalent if they share a character. Count equivalence classes. Naive approach: compare every pair of strings for shared characters. That is . Too slow. Better: connect strings through their characters using hub nodes.
Create hub nodes (one per letter). For each string, union it with all its characters. Two strings sharing a character end up in the same component. Count distinct components among the string nodes only.