Merge Synonym Groups

Given a list of string pairs pairs, where pairs[i] = [word1, word2] means that word1 and word2 are synonyms (aliases).

The synonym relation is:

  • Bidirectional: if a is a synonym of `b...

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Standard Input
Execution Result: