beats 100 % percent of users || weekly contest 397
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def maxScore(self, grid: List[List[int]]) -> int:\n        m = len(grid)\n        n = len(grid[0])\n        \n        # Initialize the maxFutureValue matrix\n        maxFutureValue = [[float(\'-inf\')] * n for _ in range(m)]\n        maxFutureValue[m - 1][n - 1] = grid[m - 1][n - 1]\n        \n        # Calculate the maxFutureValue matrix\n        for i in range(m - 1, -1, -1):\n            for j in range(n - 1, -1, -1):\n                if i < m - 1:\n                    maxFutureValue[i][j] = max(maxFutureValue[i][j], maxFutureValue[i + 1][j])\n                if j < n - 1:\n                    maxFutureValue[i][j] = max(maxFutureValue[i][j], maxFutureValue[i][j + 1])\n                maxFutureValue[i][j] = max(maxFutureValue[i][j], grid[i][j])\n        \n        # Calculate the maxScore\n        maxScore = float(\'-inf\')\n        for i in range(m):\n            for j in range(n):\n                if i < m - 1:\n                    maxScore = max(maxScore, maxFutureValue[i + 1][j] - grid[i][j])\n                if j < n - 1:\n                    maxScore = max(maxScore, maxFutureValue[i][j + 1] - grid[i][j])\n        \n        return maxScore\n\n```
['Python3']