2695. Find Score of an Array After Marking All Elements
My accepted Python solution to LeetCode problem 2695, Find Score of an Array After Marking All Elements, running in 486ms.
- Difficulty: Medium
- Python
- Runtime 486ms
- Memory 38.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 486ms, memory 38.9MB, accepted 2025-12-31.
class Solution:
def findScore(self, nums: List[int]) -> int:
import heapq
n = len(nums)
marked = [False] * n
# Min heap: (value, index)
heap = [(nums[i], i) for i in range(n)]
heapq.heapify(heap)
score = 0
while heap:
val, idx = heapq.heappop(heap)
if marked[idx]:
continue
score += val
marked[idx] = True
# Mark adjacent elements
if idx > 0:
marked[idx - 1] = True
if idx < n - 1:
marked[idx + 1] = True
return score