Untitled

 avatar
unknown
plain_text
2 years ago
451 B
3
Indexable
from functools import lru_cache
class Solution:
    def maxDotProduct(self, a: List[int], b: List[int]) -> int:
        @lru_cache(None)
        def dp(i, j):
            if i < 0 or j < 0:
                return -math.inf
            return max(
                a[i] * b[j],
                a[i] * b[j] + dp(i - 1, j - 1),
                dp(i, j - 1),
                dp(i - 1, j)
            )
        return dp(len(a) - 1, len(b) - 1)
Editor is loading...
Leave a Comment