← 返回 snapchat 的题目列表Cluster Score Difference
类型:online_judge
There are n people, each having an integer score. Given a list of relations where each element is a list of two integers [a, b] indicating a and b are friends, find the difference between the maximum and minimum scores in each connected component (friend cluster).
Input: relations = [[0, 1], [1, 2], [3, 4]] scores = [10, 20, 30, 25, 24]
Output: [20, 1]
Explanation:
The first friend cluster contains 0, 1, 2 with scores [10, 20, 30], the maximum difference is 30 - 10 = 20
The second friend cluster contains 3, 4 with scores [25, 24], the maximum difference is 25 - 24 = 1.
Example
Input
0 1
1 2
3 4
10 20 30 25 24