3788. Maximum Unique Subarray Sum After Deletion
My accepted Python solution to LeetCode problem 3788, Maximum Unique Subarray Sum After Deletion, running in 2ms.
- Difficulty: Easy
- Python
- Runtime 2ms
- Memory 16.9MB
- 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 2ms, memory 16.9MB, accepted 2025-12-31.
class Solution:
def maxSum(self, nums: List[int]) -> int:
# Get unique positive elements
positive = set(x for x in nums if x > 0)
if positive:
return sum(positive)
# If no positive, return maximum element (including 0 or least negative)
return max(nums)