class Solution:
def maxTotalReward(self, rewardValues: List[int]) -> int:
rewardValues.sort()
possible = set()
for r in rewardValues:
dp = possible.copy()
for val in possible:
if val<r:
dp.add(val+r)
dp.add(r)
possible = dp
return max(possible)
The time complexity of the algorithm is O(n^2) where n is the length of the rewardValues list. This is because for each reward value, the algorithm iterates over all previously calculated possible values.
The space complexity is also O(n^2) because a new set of possible values is created for each reward value.