2067. Maximum Number of Points with Cost
My accepted Python solution to LeetCode problem 2067, Maximum Number of Points with Cost, running in 391ms.
- Difficulty: Medium
- Python
- Runtime 391ms
- Memory 40.2MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 391ms, memory 40.2MB, accepted 2025-12-29.
class Solution:
def maxPoints(self, points: List[List[int]]) -> int:
m, n = len(points), len(points[0])
dp = points[0][:]
for i in range(1, m):
# Left to right max
left = [0] * n
left[0] = dp[0]
for j in range(1, n):
left[j] = max(left[j-1] - 1, dp[j])
# Right to left max
right = [0] * n
right[n-1] = dp[n-1]
for j in range(n-2, -1, -1):
right[j] = max(right[j+1] - 1, dp[j])
# Update dp
for j in range(n):
dp[j] = points[i][j] + max(left[j], right[j])
return max(dp)