1947. Maximum Compatibility Score Sum (Medium) - TengnanYao/daily_leetcode GitHub Wiki
class Solution(object):
def maxCompatibilitySum(self, students, mentors):
"""
:type students: List[List[int]]
:type mentors: List[List[int]]
:rtype: int
"""
n = len(students)
sums = []
for s in students:
temp = []
for m in mentors:
temp.append(sum([s[i] == m[i] for i in range(len(s))]))
sums.append(temp)
perm = list(permutations(range(0, n)))
result = 0
for p in perm:
result = max(result, sum([sums[i][p[i]] for i in range(n)]))
return result