← 返回 snapchat 的题目列表Union of Groups for Pairings
类型:online_judge
Given a list, each element is a pair of integers, representing two elements belonging to the same group. Design a function to find how many cross-group pairings can be formed. Example: Given [(1, 2), (2, 3), (4, 5)], which represents 1 and 2 are in one group, 2 and 3 are in one group, and 4 and 5 are in another group. The result should be the total pairs possible to form between the different groups. In this example, the answer should be (1, 4), (1, 5), (2, 4), (2, 5), (3, 4), (3, 5), totaling 6 pairs because 1, 2, 3 are in one group and 4, 5 in another.
Example:
Input: [[(1, 2), (2, 3), (4, 5)]]
Output: 6
Explanation: Group 1 includes 1, 2, 3; Group 2 includes 4, 5. Thus, there are 6 combinations across groups.
Example
Input
{"pairs": [[1, 2], [2, 3], [4, 5]]}