Find Score of an Array After Marking All Elements

Medium · Heap & Priority Queue · about 20 minutes

Asked at Google, Amazon, Microsoft.

Your score starts at 0. Until every element of nums is marked, find the smallest value that is still unmarked (taking the leftmost one on ties), add it to your score, and mark it together with its immediate left and right neighbors (where they exist). Return the final score.

Related guides