TikTok Twin Pairs
The TikTok development team is working on a feature to help creators come up with better captions for their videos. TikTok's algorithm favors engaging captions, so you are building an AI tool that paraphrases captions to make them catchier.
However, TikTok charges creators based on the number of characters that get changed after paraphrasing. Therefore, you are tasked with reducing TikTok creators' costs by identifying 'twin-strings' from the captions to avoid paraphrasing the same content multiple times.
Two strings are considered as 'twin-strings' if they are composed of the same characters, regardless of their arrangement or frequency.
For example, "viral" and "rival" are 'twin-strings' since both are composed of the same five characters: 'v', 'i', 'r', 'a', and 'l'. However, "viral" and "trendy" are not 'twin-strings' since they do not share all the same letters.
Given an array of n strings, determine the number of pairs (i, j) such that 0 ≤ i < j < n and (words[i], words[j]) are 'twin-strings.'
Note: Each string is composed of lowercase English characters only.
Complete the function countTwinPairs in the editor.
countTwinPairs has the following parameter(s):
string words[n]: an array ofnstrings
Returns
long: the number of valid pairs of 'twin-strings' in the given array.
1Example 1
2Example 2

Constraints
Limits and guarantees your solution can rely on.
n ≤ 10^5