Leetcode 1748 Solution

This article provides solution to leetcode question 1748 (best-team-with-no-conflicts)

https://leetcode.com/problems/best-team-with-no-conflicts

Solution

class Solution:
    def bestTeamScore(self, scores: List[int], ages: List[int]) -> int:
        data = list(zip(ages, scores))
        data.sort()

        dp = []
        for i in range(len(data)):
            opt = data[i][1]

            for j in range(i):
                if data[i][1] >= data[j][1]:
                    opt = max(opt, data[i][1] + dp[j])

            dp.append(opt)

        return max(dp)