2291. Maximum Profit From Trading Stocks

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 2291

class Solution:
    def maximumProfit(self, present: List[int], future: List[int], budget: int) -> int:
        f = [0] * (budget + 1)
        for a, b in zip(present, future):
            for j in range(budget, a - 1, -1):
                f[j] = max(f[j], f[j - a] + b - a)
        return f[-1]