Best Team With No Conflicts LeetCode solution in Python
1# Runtime: 5727 ms (Top 5.11%) | Memory: 14.3 MB (Top 62.50%)2class Solution(object):3def bestTeamScore(self, scores, ages):4"""5:type scores: List[int]6:type ages: List[int]7:rtype: int8"""9l = len(scores)10mapped = [[ages[i], scores[i]] for i in range(l)]11mapped = sorted(mapped, key=lambda x: (x[0], x[1]))12dp = [i[1] for i in mapped]1314for i in range(l):15for j in range(0, i):16if mapped[j][1] <= mapped[i][1]:17dp[i] = max(dp[i], mapped[i][1] + dp[j])18elif mapped[i][0] == mapped[j][0]:19dp[i] = max(dp[i], mapped[i][1] + dp[j])2021return max(dp)