Maximum Total Importance of Roads LeetCode solution in Python
1class Solution:2def maximumImportance(self, n: int, roads: List[List[int]]) -> int:3Arr = [0] * n # i-th city has Arr[i] roads4for A, B in roads:5Arr[A] += 1 # Each road increase the road count6Arr[B] += 17Arr.sort() # Cities with most road should receive the most score8summ = 09for i in range(len(Arr)):10summ += Arr[i] * (i + 1) # Multiply city roads with corresponding score1112return summ