It all depends what you mean by common characters. Do “CAMPBELL” and “RITCHIE” have C and E as common characters because C and E both appear? Or do they have no common characters because the first two characters are different, the second two different, etc. In the latter case “three” and “ether” would have one e in common, as the 4th character, which can be found as pairs in linear time by iterating the
String. If you use the set solution above, you will get 4 duplicates: ehrt, because those two words are anagrams of each other.
But that Set thing is a good solution, which will also run in linear time.