Leetcode Problem 2593. Find Score of an Array After Marking All Elements
2593. Find Score of an Array After Marking All Elements
Leetcode Solutions
Priority Queue with Visited Array
Initialize a priority queue (min heap) to store pairs of (value, index) from the input array nums.
Initialize a visited array of the same length as nums with all elements set to False.
Push all elements of nums along with their indices into the priority queue.
Initialize score to 0.
While the priority queue is not empty:
a. Pop the top element (smallest unmarked element) from the priority queue.
b. If the element at the popped index is unmarked (visited array is False at that index):
i. Add the value to score.
ii. Mark the element and its adjacent elements as visited.