← 返回 netflix 的题目列表Count the Number of String Pairs With No Common Characters
类型:online_judge
Given a list of strings words, count the number of distinct unordered pairs of indices (i, j) with i < j such that the two strings share no common characters.
Count index pairs (even if two strings have the same content, different positions are treated as different elements).
Requirement: aim for a solution close to O(n log n) as requested by the interviewer.
Example
Input: ["apple", "banana", "peach", "kiwi"] Output: 3 Explanation: valid pairs are:
("apple", "kiwi")
("banana", "kiwi")
("peach", "kiwi")
Constraints (can be clarified/assumed during the interview)
1 <= n <= 2e5 (discussion acceptable)
Character set: assume lowercase a-z (otherwise discuss bitsets/hashing)
Return the count.
Example
Input
apple
banana
peach
kiwi
Output
3