Count String Pairs With Disjoint Characters
Problem statement
Given an array of strings words, return the number of unordered index pairs (i, j) such that i < j and the two strings share no character.
For this exercise, assume every array index is a distinct candidate, even when two strings have equal values. Every string contains only lowercase English letters and may be empty. An empty string shares no character with any string.
Function
countDisjointCharacterPairs(words: String[]) → intExamples
Example 1
words = ["abc","def","ad","xyz"]return = 4The valid pairs are (0,1), (0,3), (1,3), and (2,3).
Example 2
words = ["a","a","b",""]return = 5The two equal a values occupy different indices. Each pairs with b and the empty string, while b also pairs with the empty string.
Example 3
words = []return = 0An empty array contains no index pair.
Constraints
0 <= words.length <= 50000 <= sum(words[i].length) <= 200000- Every string contains only lowercase English letters and may be empty.
- Each array index is counted as a distinct candidate.