Count Pairs Of Similar Strings
You are given a 0-indexed string array words.
Two strings are similar if they consist of the same characters.
- For example,
"abca"and"cba"are similar since both consist of characters'a','b', and'c'. - However,
"abacba"and"bcfd"are not similar since they do not consist of the same characters.
Return the number of pairs (i, j) such that 0 <= i < j <= words.length - 1 and the two strings words[i] and words[j] are similar.
Example 1
Input
words = ["aba","aabb","abcd","bac","aabc"]Output
2There are 2 valid pairs: indices 0 and 1 both use only
'a' and 'b', and indices 3 and 4 both use only 'a', 'b', and 'c'.Example 2
Input
words = ["aabb","ab","ba"]Output
3All three pairs consist only of the characters
'a' and 'b', so every pair is similar.Constraints
- 1 <= words.length <= 100
- 1 <= words[i].length <= 100
- words[i] consist of only lowercase English letters.