Best Team With No Conflicts LeetCode solution in Python

1
# Runtime: 5727 ms (Top 5.11%) | Memory: 14.3 MB (Top 62.50%)
2
class Solution(object):
3
def bestTeamScore(self, scores, ages):
4
"""
5
:type scores: List[int]
6
:type ages: List[int]
7
:rtype: int
8
"""
9
l = len(scores)
10
mapped = [[ages[i], scores[i]] for i in range(l)]
11
mapped = sorted(mapped, key=lambda x: (x[0], x[1]))
12
dp = [i[1] for i in mapped]
13

14
for i in range(l):
15
for j in range(0, i):
16
if mapped[j][1] <= mapped[i][1]:
17
dp[i] = max(dp[i], mapped[i][1] + dp[j])
18
elif mapped[i][0] == mapped[j][0]:
19
dp[i] = max(dp[i], mapped[i][1] + dp[j])
20

21
return max(dp)

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0