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.
words = ["abca", "abaa", "baab", "cba"] return = 2
words = ["apple", "apel", "silent", "listen", "papel"] return = 4

n ≤ 10^5- Count Cyclic Digit PairsOA · Seen Jun 2026
- Count Skipped Numbers After SubtractionsOA · Seen Jun 2026
- Event ID Check Completion TimesOA · Seen Jun 2026
- Check Even-Position MonotonicityOA · Seen Jun 2026
- Count Alternating Tile GroupsOA · Seen Jun 2026
- Count Even-Digit NumbersOA · Seen Jun 2026
- Inventory Discount TrackerOA · Seen Jun 2026
- Construct WDL StringOA · Seen Jun 2026
public long countTwinPairs(String[] words) {
// write your code here
}