Two strings are said to be similar if they are composed of the same characters. For example "abaca"
and "cba"
are similar since both of them are composed of characters 'a', 'b' and 'c'. However "abaca"
and "bcd"
are not similar since they do not share all of the same letters.
Given an array of strings words
of length n
, find the number of pairs of strings that are similar.
Note:
- Each string is composed of lowercase English characters only.
- Pairs are considered index-wise, i.e., two equal strings at different indices are counted as separated pairs.
- A pair at indices
(i, j)
is the same as the pair at(j, i)
.
Function Description
Complete the function countSimilarPairs
in the editor below.
countSimilarPairs
has the following parameter:
string words[n]
: an array ofn
strings
Returns
long integer
: the number of similar pairs
Example 1:
Input: words = ["xyz", "foo", "of"]
Output: 1
Explanation:Here, the strings
"foo"
and"of"
are similar because they are composed of the same characters ['o', 'f']. There are no other similar pairs so the answer is 1.
- 1 ≤
n
≤ 10^5 - The Sum of the lengths of all strings does not exceed 10^6.
- All strings consist of lowercase English characters only.

input:
output: